|
1 |
| -## API Explorer |
| 1 | +### Using the API Explorer |
2 | 2 |
|
3 |
| -LoopBack helps you build APIs for mobile applications. As you follow the steps |
4 |
| -to create a project and add models using the `slc lb` command line tool, REST |
5 |
| -APIs are automatically added to your application. |
6 |
| - |
7 |
| -Now we have a handful of REST APIs. It would be nice to see the list of APIs and |
8 |
| -try them out without writing code. We can do that! LoopBack provides a Web based |
9 |
| -API explorer out of the box to document and explore REST APIs for the models. |
10 |
| - |
11 |
| -Let's give a try first. |
12 |
| - |
13 |
| -### API Explorer UI |
14 |
| - |
15 |
| -Step 1: Run the sample application |
16 |
| - |
17 |
| - $ cd sls-sample-app |
18 |
| - $ slc run app |
19 |
| - |
20 |
| - |
21 |
| -Step 2: Open your browser and point to http://localhost:3000/explorer. You'll |
22 |
| -see a list of REST API endpoints as illustrated below. |
23 |
| - |
24 |
| - |
| 3 | +Follow these steps to explore the sample app's REST API: |
25 | 4 |
|
| 5 | +1. Open your browser to http://localhost:3000/explorer. You'll see a list of REST API endpoints as illustrated below. |
| 6 | +<img src="assets/explorer-listing.png" alt="API Explorer Listing" width="600" style="border: 1px solid gray; padding: 5px; margin: 10px;"> |
26 | 7 | The endpoints are grouped by the model names. Each endpoint consists of a list
|
27 | 8 | of operations for the model.
|
| 9 | +2. Click on one of the endpoint paths (such as /locations) to see available |
| 10 | +operations for a given model. You'll see the CRUD operations mapped to HTTP verbs and paths. |
| 11 | +<img src="assets/explorer-endpoint.png" alt="API Exlporer Endpoints" width="600" style="border: 1px solid gray; padding: 5px; margin: 10px;"> |
| 12 | +3. Click on a given operation to see the signature; for example, GET `/locations/{id}`: |
| 13 | +<img src="assets/explorer-api.png" alt="API Spec" width="600" style="border: 1px solid gray; padding: 5px; margin: 10px;"> |
| 14 | +Notice that each operation has the HTTP verb, path, description, response model, and a list of request parameters. |
| 15 | +4. Invoke an operation: fill in the parameters, then click the **Try it out!** button. You'll see something like this: |
28 | 16 |
|
29 |
| -Step 3: Click on one of the endpoint paths (such as /locations) to see available |
30 |
| -operations for a given model. |
31 |
| - |
32 |
| - |
33 |
| - |
34 |
| -Great, now you see the CRUD operations mapped to HTTP verbs and paths. |
35 |
| - |
36 |
| -Step 4: Click on a given operation to see the signature |
37 |
| - |
38 |
| - |
39 |
| - |
40 |
| -Please note each operation has the HTTP verb, path, description, response model, |
41 |
| -and a list of request parameters. |
42 |
| - |
43 |
| -Step 5: Try to invoke an operation |
44 |
| - |
45 |
| -Fill in the parameters, and then click on `Try it out!` button. |
46 |
| - |
47 |
| -Here we go: |
48 |
| - |
49 |
| - |
50 |
| - |
51 |
| -Cool, we can invoke the REST APIs without writing code! |
52 |
| - |
53 |
| -You might be curious about the magic behind it all. Let's reveal a bit to you. |
54 |
| - |
55 |
| -### REST API specs |
56 |
| - |
57 |
| -LoopBack API Explorer is built on top of the popular |
58 |
| -[Swagger Framework](https://github.com/wordnik/swagger-core/wiki). There are two |
59 |
| -components involved. |
60 |
| - |
61 |
| -1. LoopBack builds up formal specifications of the REST APIs using the knowledge of |
62 |
| -model definitions, JavaScript method declarations, and remote mappings. The |
63 |
| -specifications are served over the following endpoints. |
64 |
| - |
65 |
| -2. The wonderful Web UI is brought you by [Swagger UI](https://github.com/strongloop/swagger-ui). |
66 |
| -Swagger UI is a collection of HTML, Javascript, and CSS assets that dynamically |
67 |
| -generate beautiful documentation and sandbox from the REST API specifications. |
68 |
| - |
69 |
| -#### Resource Listing |
70 |
| -The first part is a listing of the REST APIs. |
71 |
| - |
72 |
| -- http://localhost:3000/swagger/resources |
73 |
| - |
74 |
| - |
75 |
| - { |
76 |
| - "swaggerVersion": "1.1", |
77 |
| - "basePath": "http://localhost:3000", |
78 |
| - "apis": [ |
79 |
| - { |
80 |
| - "path": "/swagger/ammo" |
81 |
| - }, |
82 |
| - { |
83 |
| - "path": "/swagger/customers" |
84 |
| - }, |
85 |
| - { |
86 |
| - "path": "/swagger/inventory" |
87 |
| - }, |
88 |
| - { |
89 |
| - "path": "/swagger/locations" |
90 |
| - }, |
91 |
| - { |
92 |
| - "path": "/swagger/weapons" |
93 |
| - } |
94 |
| - ] |
95 |
| - } |
| 17 | +<img src="assets/explorer-req-res.png" alt="Request/Response" width="400" style="border: 1px solid gray; padding: 5px; margin: 10px 10px 10px 100px;"> |
96 | 18 |
|
97 |
| -#### Resource Operations |
98 |
| -The second part describes all operations of a given model. |
| 19 | +You can see the request URL, the JSON in the response body, and the HTTP response code and headers. |
99 | 20 |
|
100 |
| -- http://localhost:3000/swagger/locations |
| 21 | +<h3>Next Steps</h3> |
101 | 22 |
|
| 23 | +To gain a deeper understanding of LoopBack and how it works, read the following sections, [Working with Models](#working-with-models) and [Working with Data Sources and Connectors](#working-with-data-sources-and-connectors). |
102 | 24 |
|
103 |
| - { |
104 |
| - "swaggerVersion": "1.1", |
105 |
| - "basePath": "http://localhost:3000", |
106 |
| - "apis": [ |
107 |
| - { |
108 |
| - "path": "/locations", |
109 |
| - "operations": [ |
110 |
| - { |
111 |
| - "httpMethod": "POST", |
112 |
| - "nickname": "locations_create", |
113 |
| - "responseClass": "object", |
114 |
| - "parameters": [ |
115 |
| - { |
116 |
| - "paramType": "body", |
117 |
| - "name": "data", |
118 |
| - "description": "Model instance data", |
119 |
| - "dataType": "object", |
120 |
| - "required": false, |
121 |
| - "allowMultiple": false |
122 |
| - } |
123 |
| - ], |
124 |
| - "errorResponses": [], |
125 |
| - "summary": "Create a new instance of the model and persist it into the data source", |
126 |
| - "notes": "" |
127 |
| - } |
128 |
| - ] |
129 |
| - }, |
130 |
| - ... |
131 |
| - { |
132 |
| - "path": "/locations/{id}", |
133 |
| - "operations": [ |
134 |
| - { |
135 |
| - "httpMethod": "GET", |
136 |
| - "nickname": "locations_findById", |
137 |
| - "responseClass": "any", |
138 |
| - "parameters": [ |
139 |
| - { |
140 |
| - "paramType": "path", |
141 |
| - "name": "id", |
142 |
| - "description": "Model id", |
143 |
| - "dataType": "any", |
144 |
| - "required": true, |
145 |
| - "allowMultiple": false |
146 |
| - } |
147 |
| - ], |
148 |
| - "errorResponses": [], |
149 |
| - "summary": "Find a model instance by id from the data source", |
150 |
| - "notes": "" |
151 |
| - } |
152 |
| - ] |
153 |
| - }, |
154 |
| - ... |
155 |
| - ] |
156 |
| - } |
| 25 | +For information on how StrongLoop Suite provides: |
157 | 26 |
|
158 |
| -**Note: The API specifications will be enhanced in future releases to include |
159 |
| -the model definitions.** |
| 27 | + - Out-of-the-box scalability, see |
| 28 | + [StrongNode](http://docs.strongloop.com/strongnode#quick-start). |
| 29 | + - CPU profiling and path trace features, see |
| 30 | + [StrongOps](http://docs.strongloop.com/strongops#quick-start). |
| 31 | + - Mobile client APIs, see [LoopBack Client SDKs](http://docs.strongloop.com/loopback-clients/). |
0 commit comments