This API enables users to retrieve a list of news articles about Australian companies. The source of the news will be from several sources including The Guardian, USA Tday etc.
The API conventions we aim to use are outlined in the OpenAPI specifications.
Express based RESTful News API for starter applications. This API's skeleton is based on the Yo RESTful API, with an updated authentication routine (without being transpiled using babel).
Help keep the code clean be following our contribution protocols (CONTRIBUTING.md).
Versioning will be managed by the product manager(s) and can be found in the changelog (CHANGELOG.md)
- MongoDB
- Node >7.4
- pm2 (production)
npm test # test using Jest
npm run test:unit # run unit tests
npm run test:integration # run integration tests
npm run coverage # test and open the coverage report in the browser
npm run lint # lint using ESLint
npm run dev () # run the API in development mode
npm run prod # run the API in production mode
npm run docs # generate API docs
npm run dev
HTTP BASIC Authentication returning a JWT token.
curl -X POST http://api.restfulnews.com/users -i -d "email=test@example.com&password=123456&access_token=MASTER_KEY_HERE"
curl -X POST http://api.restfulnews.com/auth -i -u test@example.com:123456 -d "access_token=MASTER_KEY_HERE"
Errors are handled by the services/error
middleware. You can pass errors within an async call by calling next(error)
where error is an Object with a Prototype of error. The APIError constructor function has been provided for creating anticipated operational errors.
Logging is achieved via Pino. In development mode we can pipe Node's stdout into Pino for pretty printing.
You can customize the src
and api
directories.
src/
├─ api/
│ ├─ user/
│ │ ├─ controller.js
│ │ ├─ index.js
│ │ ├─ index.test.js
│ │ ├─ model.js
│ │ └─ model.test.js
│ └─ index.js
├─ services/
│ ├─ express/
│ ├─ facebook/
│ ├─ mongoose/
│ ├─ passport/
│ ├─ sendgrid/
│ └─ your-service/
├─ app.js
├─ config.js
└─ index.js
Here is where the API endpoints are defined. Each API has its own folder.
It defines the Mongoose schema and model for the API endpoint. Any changes to the data model should be done here.
This is the API controller file. It defines the main router middlewares which use the API model.
This is the entry file of the API. It defines the routes using, along other middlewares (like session, validation etc.), the middlewares defined in the some-endpoint.controller.js
file.
Here you can put helpers
, libraries
and other types of modules which you want to use in your APIs.
- Clone repo to
/srv/restfulnews
(use~/.ssh/read-key
&~/.ssh/config
file) - Set environment variables file
.env
(see .env.example) - Run
restfulnews/scripts/init.sh
to set up server
docker-compose logs
Show logs- TODO: Route up proper PM2 logs to file
Environment variables from .env
are accessible by the Node app through docker-compose.yml which routes them into the api container. PM2 automatically makes them available to each Node server.