Skip to content
This repository was archived by the owner on Jan 8, 2025. It is now read-only.

Commit 7e2832e

Browse files
committed
Merge branch 'release/1.0.1'
2 parents f4d1b82 + cae00b6 commit 7e2832e

18 files changed

+891
-251
lines changed

.circleci/config.yml

+5
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ jobs:
5353
command:
5454
npm run test:server
5555

56+
- run:
57+
name: Mutation Tests
58+
command:
59+
npm run test:mutants
60+
5661
- run:
5762
name: Push any lockfile changes
5863
command: greenkeeper-lockfile-upload

README.md

+54-19
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22

33
A stripped down generic API boilerplate built around NodeJS and Swagger V3.
44

5+
[![Greenkeeper badge](https://badges.greenkeeper.io/davesag/api-server-boilerplate.svg)](https://greenkeeper.io/)
6+
57
## Branches
68

7-
| Branch | Tests | Code Coverage | Comments |
8-
| --------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------- |
9-
| `develop` | [![CircleCI](https://circleci.com/gh/davesag/api-server-boilerplate/tree/develop.svg?style=svg)](https://circleci.com/gh/davesag/api-server-boilerplate/tree/develop) | [![codecov](https://codecov.io/gh/davesag/api-server-boilerplate/branch/develop/graph/badge.svg)](https://codecov.io/gh/davesag/api-server-boilerplate) | Work in progress |
10-
| `master` | [![CircleCI](https://circleci.com/gh/davesag/api-server-boilerplate/tree/master.svg?style=svg)](https://circleci.com/gh/davesag/api-server-boilerplate/tree/master) | [![codecov](https://codecov.io/gh/davesag/api-server-boilerplate/branch/master/graph/badge.svg)](https://codecov.io/gh/davesag/api-server-boilerplate) | Latest Production Release |
9+
<!-- prettier-ignore -->
10+
| Branch | Tests | Code Coverage | Comments |
11+
| ------ | ----- | ------------- | -------- |
12+
| `develop` | [![CircleCI](https://circleci.com/gh/davesag/api-server-boilerplate/tree/develop.svg?style=svg)](https://circleci.com/gh/davesag/api-server-boilerplate/tree/develop) | [![codecov](https://codecov.io/gh/davesag/api-server-boilerplate/branch/develop/graph/badge.svg)](https://codecov.io/gh/davesag/api-server-boilerplate) | Work in progress |
13+
| `master` | [![CircleCI](https://circleci.com/gh/davesag/api-server-boilerplate/tree/master.svg?style=svg)](https://circleci.com/gh/davesag/api-server-boilerplate/tree/master) | [![codecov](https://codecov.io/gh/davesag/api-server-boilerplate/branch/master/graph/badge.svg)](https://codecov.io/gh/davesag/api-server-boilerplate) | Latest Production Release |
1114

1215
## Configuration
1316

@@ -19,49 +22,78 @@ Set the following environment variables
1922

2023
## API Routes
2124

22-
There's a single API route, `/api/v1/ping` that simply returns some information about the server.
25+
If it's running locally (see below) point a browser at any of the following routes:
26+
27+
- [localhost:8282](http://127.0.0.1:8282)
28+
- [localhost:8282/ping](http://127.0.0.1:8282/ping)
29+
- [localhost:8282/api/v1/hello/some name](http://127.0.0.1:8282/api/v1/hello/some%20name)
30+
31+
and see the API docs at
2332

24-
If it's running locally (see below) point a browser at [localhost:8282/api/v1/ping](http://127.0.0.1:8282/api/v1/ping).
33+
- [localhost:8282/docs](http://127.0.0.1:8282/docs)
2534

2635
## What's the point of this?
2736

28-
I write a lot of APIs and have distilled my current best-practice into this codebase to save myself time.
37+
I write a lot of APIs and have distilled my current best-practice into this codebase to save myself time, and as example code for other developers wondering how to do this sort of stuff.
38+
39+
## What do you do with it?
2940

3041
Just clone it or fork it, nuke the existing `.git` data and replace with your own `git init` and `git flow init` edit the `README.md` file, add your own details to `api.yml` and add routes to `src/api/` as you like.
3142

32-
## What's not in this
43+
## What's included?
3344

34-
Heaps. I've paired this right back to the simplest, most generic API I could, so there's no
45+
- a couple of root-level API routes and simple controllers
3546

36-
- authentication (add `passport` and update `src/utils/makeApp` and add appropriate security blocks to `api.yml`)
37-
- middleware (roll your own and update `src/utils/makeApp`)
38-
- monitoring
39-
- sockets or event listeners
40-
- databases, search systems, etc
47+
- `src/api/ping`
48+
- `src/api/versions`
4149

42-
## What is in this
50+
- a versioned API route and controller
51+
52+
- `src/api/v1/hello`
4353

44-
- a single API route and simple controller (`src/api/v1/ping`)
45-
- support for asynchronous routes via [`route-async`](https://github.com/davesag/route-async)
4654
- automatic linking of swagger paths to controllers using [`swagger-routes-express`](https://github.com/davesag/swagger-routes-express) and [`traverse-folders`](https://github.com/davesag/traverse-folders)
4755
- automatic generation of API docs using [`swagger-ui-express`](https://github.com/scottie1984/swagger-ui-express)
4856
- simple logging (swap out the code in `src/utils/logger` to add your own)
4957
- standardised [`node-http-error`](https://github.com/carsondarling/node-http-error) and [`http-status-codes`](https://github.com/prettymuchbryce/http-status-codes) and simple `generic` and `notFound` error handlers
5058
- the swagger editor as an easy to invoke docker image
5159
- [`dotenv`](https://github.com/motdotla/dotenv) support
5260

53-
### Code Quality
61+
### Code quality
62+
63+
- unit testing using
64+
65+
- [`mocha`](https://mochajs.org),
66+
- [`sinon`](https://sinonjs.org),
67+
- [`chai`](https://www.chaijs.com), and
68+
- [`proxyquire`](https://github.com/thlorenz/proxyquire)
5469

55-
- unit testing via [`mocha`](https://mochajs.org), [`sinon`](https://sinonjs.org), [`chai`](https://www.chaijs.com), and [`proxyquire`](https://github.com/thlorenz/proxyquire)
5670
- `request` and `response` mocks using [`mock-req-res`](https://github.com/davesag/mock-req-res)
5771
- 100% unit test coverage using [`nyc`](https://github.com/istanbuljs/nyc)
5872
- integration testing using [`supertest`](https://github.com/visionmedia/supertest)
5973
- code quality using [`eslint`](https://eslint.org) and [`prettier`](https://prettier.io)
74+
- mutation testing with [`stryker-mutator`](https://stryker-mutator.io)
6075
- [`circleci`](https://circleci.com) integration
6176
- [`greenkeeper`](https://greenkeeper.io) integration
6277

78+
## What's not included?
79+
80+
I've paired this right back to the simplest, most generic API I could, so there's no
81+
82+
- authentication (add `passport` and update `src/utils/makeApp` and add appropriate security blocks to `api.yml`)
83+
- example of an asynchronous route via [`route-async`](https://github.com/davesag/route-async)
84+
- rate limiting
85+
- middleware (roll your own and update `src/utils/makeApp`)
86+
- monitoring
87+
- sockets or event listeners
88+
- databases, search systems, etc
89+
6390
## Development
6491

92+
### Prerequisites
93+
94+
- [NodeJS](htps://nodejs.org), version 10.15.3 (LTS) or better. (I use [`nvm`](https://github.com/creationix/nvm) to manage Node versions — `brew install nvm`.)
95+
- [Docker](https://www.docker.com) if you want to use the Swagger Editor. (Use [Docker for Mac](https://docs.docker.com/docker-for-mac/), not the `homebrew` version)
96+
6597
### To build and run locally
6698

6799
Clone this (or better yet, fork it then clone your fork)
@@ -83,13 +115,16 @@ You can put environment variables in a `.env` file.
83115
| -------------- | ------ | ----------------- | ------------------ |
84116
| Swagger Editor | `8080` | `npm run swagger` | The swagger editor |
85117

118+
Copy and paste the `api.yml` file into the editor to edit it.
119+
86120
### Testing
87121

88122
- `npm test` to run the unit tests
89123
- `npm run test:server` will run the integration tests
90124
- `npm run lint` will lint it
91125
- `npm run prettier` will prettify it
92126
- `npm run test:unit:cov` will run the unit tests with code coverage
127+
- `npm run test:mutants` will run the unit tests with mutation testing
93128

94129
## Contributing
95130

api.yml

+73-1
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,70 @@ info:
1010
version: 1.0.0
1111
servers:
1212
- url: /api/v1
13+
tags:
14+
- name: root
15+
description: Root level API paths
16+
- name: v1
17+
description: Version 1 API Paths
1318
paths:
19+
/:
20+
get:
21+
tags:
22+
- root
23+
servers:
24+
- url: /
25+
summary: Display API version information
26+
operationId: versions
27+
responses:
28+
200:
29+
description: Information about the available API Versions
30+
content:
31+
application/json:
32+
schema:
33+
$ref: '#/components/schemas/VersionResponse'
1434
/ping:
1535
get:
36+
tags:
37+
- root
38+
servers:
39+
- url: /
1640
summary: Checks that the server is alive
17-
operationId: v1/ping
41+
operationId: ping
1842
responses:
1943
200:
2044
description: 'Information about the server'
2145
content:
2246
application/json:
2347
schema:
2448
$ref: '#/components/schemas/PingResponse'
49+
/hello/{name}:
50+
get:
51+
tags:
52+
- v1
53+
summary: Say hello to the name provided
54+
operationId: v1/hello
55+
parameters:
56+
- in: path
57+
name: name
58+
description: 'The name to say hello to'
59+
schema:
60+
type: string
61+
required: true
62+
responses:
63+
200:
64+
description: 'Just says hello'
65+
content:
66+
application/json:
67+
schema:
68+
$ref: '#/components/schemas/HelloWorldResponse'
69+
400:
70+
description: 'Bad request —Invalid name supplied'
71+
content:
72+
application/json:
73+
schema:
74+
$ref: '#/components/schemas/ErrorResponse'
2575
components:
76+
schemas:
2677
PingResponse:
2778
type: object
2879
properties:
@@ -34,3 +85,24 @@ components:
3485
type: string
3586
uptime:
3687
type: number
88+
APIVersion:
89+
type: object
90+
properties:
91+
version:
92+
type: integer
93+
description: The API's version number
94+
path:
95+
type: string
96+
description: The relative path to the API
97+
VersionResponse:
98+
type: array
99+
items:
100+
$ref: '#/components/schemas/APIVersion'
101+
HelloWorldResponse:
102+
type: string
103+
ErrorResponse:
104+
type: object
105+
properties:
106+
error:
107+
type: string
108+
description: The error message

0 commit comments

Comments
 (0)