UNPKG

3 kBMarkdownView Raw
1## Quick start
2
3Let's see how easily and quickly you can get a simple API up and running using swagger.
4
5* [Get an API up and running](#upandrunning)
6* [Check out the main Node.js app file](#main)
7* [Open the Swagger editor](#openeditor)
8* [Windows users](#windows)
9
10### <a name="upandrunning"></a>Get an API up and running
11
12First, we create a new swagger project and test a simple "hello world" API.
13
141. Install swagger, as described in the [installation guide](install.md).
15
162. Create swagger project directory and cd to it. This is where you'll create your first project.
17
183. Execute the project create command:
19
20 `swagger project create hello-world`
21
224. Pick the API framework you want to use. We're going to pick express, but you can pick any of the listed frameworks:
23 ```
24 ? Framework? (Use arrow keys)
25 connect
26 ❯ express
27 hapi
28 restify
29 sails
30 ```
315. swagger creates a skeleton project that's pre-configured to use your selected framework (in this example, Express). It then runs `npm install` to pick up the dependencies.
32
33 Note: Windows users see the [note below](#windows-note) regarding npm.
34
356. Change to the new project directory: `cd hello-world`
36
377. Type `swagger project start` to start your API. You now have an API running with swagger!
38
398. In another terminal, run this command:
40
41 `curl http://127.0.0.1:10010/hello?name=Scott`
42
43 And, you'll get back the response `Hello, Scott`.
44
45That's it - You have now created, started and tested your first API project with swagger!
46
47### <a name="main"></a>Check out the main Node.js app file
48
49Open <project-root>/app.js in an editor. This is the main Node.js app that installs middleware and requires the API framework that you chose when you created your project.
50
51The middleware modules perform tasks like Swagger specification validation and endpoint routing. For more information, see [swagger modules and dependencies](./modules.md).
52
53### <a name="openeditor"></a>Open the Swagger editor
54
55The Swagger editor lets you design and test your API interactively. While you design and test, the API documentation is generated automatically for you.
56
57Now that we've got our basic API running, let's open the Swagger editor.
58
591. Be sure you're in your project root directory: `./hello-world`.
60
612. Fire up the editor: `swagger project edit`
62
63*The Swagger editor*
64![alt text](./images/swagger-editor.png)
65
66
67### <a name='windows'></a>Windows users
68For some versions of npm on Windows will have problems on the `npm install` step of `swagger project create`. They are related to a `debug` module on npm not being managed properly. The following steps should resolve this issue:
69
701. In the project directory, execute the following commands:
71 1. `npm install yamljs`
72 2. `npm install debug`
73 3. `npm install swagger-tools`
74
75Now, when you run `swagger project start` your project should start successfully.