###1. 新建应用### 命令行首先定位到应用所在的路径,执行 yo loopback
根据提示:
? What's the name of your application? study
? Enter name of the directory to contain the project: study
输入应用名称和应用目录(按回车默认与名称一致)
之后开始自动初始化项目。
#####初始化完成后提示:
Next steps:
Change directory to your app $ cd study
Create a model in your app $ yo loopback:model
Optional: Enable StrongOps monitoring $ slc strongops
Run the app $ node .
2.新建数据模型###
执行 yo loopback:model
(新建数据模型的命令) ? Enter the model name: CoffeeShop
(输入数据模型的名称)? Select the data-source to attach CoffeeShop to: db (memory)
(输入连接数据模型的数据源)? Select model's base class: PersistedModel
(选择数据模型的基类,详见LoopBack 核心概念-数据模型)? Expose CoffeeShop via the REST API? Yes
(是否需要自动生成REST API)? Custom plural form (used to build REST URL):
(定义模型的属性)Let's add some CoffeeShop properties now.
Enter an empty property name when done.
? Property name: name
(输入属性名称) invoke loopback:property
? Property type: string
(选择属性的数据类型)? Required? Yes
(选择是否必填)
Let's add another CoffeeShop property.
Enter an empty property name when done.
? Property name: (直接回车,表示
3. 运行###
执行 slc run
INFO strong-agent native addon missing, install a compiler INFO strong-agent v1.6.0 profiling app 'study' pid '15348' INFO strong-agent[15348] started profiling agent INFO supervisor reporting metrics to internal:
supervisor running without clustering (unsupervised) INFO strong-agent not profiling, agent metrics requires a valid license. Please contact sales@strongloop.com for assistance. Browse your REST API at http://localhost:3000/explorer Web server listening at: http://localhost:3000/
4. 使用API Explorer###
http://localhost:3000/explorer/
可以构造并执行请求,完成常用的CRUD操作。