Table of Contents generated with DocToc
npm install -g loopback-cli
- Create application with lb app
- Create a datasource with lb datasource
- Create model with lb model (properties can be added during the creation process)
- Create model properties (after creation) with lb property
- Create relations between models with lb relation
- Create new API methods with lb remote-method
- Create ACL with lb acl
- Create a boot script with lb boot-script (generated script example: server/boo/create-access-token.js)
To create a test datasources, create server/datasources.test.json and set the environment variable NODE_ENV=test
Add MongoDB connector:
yarn add loopback-connector-mongodb
Ceate datasource:
lb datasource
lb remote-method
This function is used to extend functionality of models by defining new methods.
If we add a buy method on product:
- A new endpoint /Products/{id}/buy is automatically created on the API
- We have to declare and implement the buy method on the prototype of the Product model
During the remote method creation, the generator asks for:
- The request arguments (request fields)
- The response arguments (response fields)
Create user by posting on "/Users":
{
"email": "<email>",
"password": "<password>"
}
Get an authentication token by posting on "/Users/login":
{
"email": "<email>",
"password": "<password>"
}
See Querying data