A simple minimalistic stateless microservice built with Node.js and Express.js, with showcasing three major functionalities:
- Authentication
- JSON patching
- Image Thumbnail Generation
- Overview
- 1. 🚀 Getting Started
- 2. 🔒 Authentication
- 3. 🔖 API Versioning
- 3. 💚 HTTP Response Codes
- 4. 🔖 Resources
- 5. 📝 License
To get started, ensure that you have NodeJS installed on your local machine:
-
Clone repository or clone your own fork
git clone https://github.com/devdbrandy/minimalistic-microservice.git
-
Make a duplicate of
.env.exampleand rename to.env, then configure your credentials. NB: After creating.envfile, ensure that you setAPP_PKEYto any secret phrase you want. -
Install dependencies by running
npm iornpm installon your terminal. -
Two npm scripts are availiable to spin up the app server:
npm run startspin up the server without watching for any file changesnpm run servewatches for any file changes and reloads the server
To test or consume api locally, you can make use of Postman or Insomnia
Test specs are implemented using mocha + chai + sinon.
Two npm scripts are available to run the test suite:
npm tornpm test- Performs a single full test suite run, including instanbul code coverage reporting. Summary coverage reports are written to stdout, and detailed HTML reports are available in/coverage/index.htmlnpm run test:watch- This watches for any file changes and runs the full test suite.
Access to restricted API endpoints requires an access token. To obtain your access token, make a request along with any dummy username and password credentials to /login.
Sample Response:
POST http://localhost:3000/login
HTTP/1.1
Accept: application/json
HTTP/1.1 200 OK
Content-Type: application/json
{
"token": "...",
}The second part of the URI specifies the API version you wish to access in the format v{version_number}.
For example, version 1 of the API (most current) is accessible via:
http://localhost:3000/api/v1Each response will be returned with one of the following HTTP status codes:
200OKThe request was successful400Bad RequestThere was a problem with the request (security, malformed)401UnauthorizedThe supplied API credentials are invalid403ForbiddenThe credentials provided do not have permissions to access the requested resource404Not FoundAn attempt was made to access a resource that does not exist in the API500Server ErrorAn error on the server occurred
| URI | HTTP Method | Description |
|---|---|---|
/login |
POST |
Account login |
| URI | HTTP Method | Description |
|---|---|---|
/api/v1/thumbnail |
POST |
Generate image thumbnail |
/api/v1/jsonpatch |
POST |
Generate json patch |
This project is open-sourced software licensed under the MIT license.