1 | ## Quick start
|
2 |
|
3 | Let'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 |
|
12 | First, we create a new swagger project and test a simple "hello world" API.
|
13 |
|
14 | 1. Install swagger, as described in the [installation guide](install.md).
|
15 |
|
16 | 2. Create swagger project directory and cd to it. This is where you'll create your first project.
|
17 |
|
18 | 3. Execute the project create command:
|
19 |
|
20 | `swagger project create hello-world`
|
21 |
|
22 | 4. 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 | ```
|
31 | 5. 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 |
|
35 | 6. Change to the new project directory: `cd hello-world`
|
36 |
|
37 | 7. Type `swagger project start` to start your API. You now have an API running with swagger!
|
38 |
|
39 | 8. 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 |
|
45 | That'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 |
|
49 | Open <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 |
|
51 | The 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 |
|
55 | The Swagger editor lets you design and test your API interactively. While you design and test, the API documentation is generated automatically for you.
|
56 |
|
57 | Now that we've got our basic API running, let's open the Swagger editor.
|
58 |
|
59 | 1. Be sure you're in your project root directory: `./hello-world`.
|
60 |
|
61 | 2. 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
|
68 | For 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 |
|
70 | 1. 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 |
|
75 | Now, when you run `swagger project start` your project should start successfully.
|