In the node JS command prompt, inside your loopback project, type the following command to create a new model.
If you have installed LoopBack CLI tool, you can create model with:
The command prompt will request informations about the model to create. In this example, a model
Foo will be created.
Enter the model name: Foo
Models can be based on one of the built-in loopback classes. Persisted models are the most common choice, representing structured data that should be stored (= persisted) inside a database.
[?] Select model's base class: (Use arrow keys) Model ❯ PersistedModel ACL AccessToken Application Change Checkpoint
It is possible to expose
Foo through a REST API. The generated API will contain methods for reading, creating, updating and deleting instances of the
[?] Expose Foo via the REST API? (Y/n) Y
To define all REST API urls for this model, Loopback uses the plural form. In the next prompt below, leaving the field empty means the
s character will be appended to the model's name
For instance, loopback will define the endpoint
But some names do not have such a plural form, such as
Repositories in plural form. In those cases, type the plural form in those fields.
[?] Custom plural form (used to build REST URL):
? Common model or server only? ❯ common server
Let's add some Foo properties now. Enter an empty property name when done. [?] Property name: name invoke loopback:property [?] Property type: (Use arrow keys) ❯ string number boolean object array date buffer geopoint (other)
[?] Required? (y/N)
localhost:3000/explorer and observe the REST API generated for