Express REST API example
 
Go to file
Raphael Cerveaux b009bdce96
Install guide
2018-11-16 17:07:33 +01:00
app Routes entry point 2018-11-15 19:28:33 +01:00
config JWT secret 2018-11-15 19:29:35 +01:00
docs API Docs 2018-11-15 19:28:51 +01:00
.eslintignore Install eslint 2018-11-13 11:15:47 +01:00
.eslintrc.json Install eslint 2018-11-13 11:15:47 +01:00
.gitignore gitignore 2018-11-12 16:26:33 +01:00
.travis.yml Travis config 2018-11-13 18:46:36 +01:00
README.md Install guide 2018-11-16 17:07:33 +01:00
index.js Error handler 2018-11-15 19:29:12 +01:00
package-lock.json Install Joi package 2018-11-13 18:49:39 +01:00
package.json Test script 2018-11-14 18:16:16 +01:00
todo.md To do list 2018-11-15 19:29:22 +01:00

README.md

API node

Build status

RESTful API based on Expressjs.

WARNING: This is for demo purposes. You should not run this in production (no cors, unit tests ...).

Features

  • Sign up/sign in (JWT, bcrypt)
  • Create, update, delete, read your notes
  • Manage your account: update, delete

Call the API

As best practice, use these headers to make requests to the API:

Content-Type:application/x-www-form-urlencoded
Accept:application/json

When signed in, you must provide the access token:

Authorization: <Access_token>

Note: The token is valid for 3 hours. After that delay you have to sign in again to get another one.

API response

The response code will never be in the response.

Make operations (create, update, delete ...)

Validation error example:

{
    "success": false,
    "message": "Form is invalid.",
    "errors": [
        {
            "message": "\"password\" is required",
            "path": [
                "password"
            ],
            "type": "any.required",
            "context": {
                "key": "password",
                "label": "password"
            }
        }
    ]
}

Getting objects (read)

{
    "_id": "5bec2fed257ab94172cd3874",
    "firstname": "Raphael",
    "lastname": "NA",
    "username": "sundown",
    "createdAt": "2018-11-14T14:23:41.581Z",
    "updatedAt": "2018-11-14T14:23:41.581Z",
    "__v": 0
}

Installation

Requirements

  • npm
  • node >= 8
  • MongoDB ~3.6
git clone https://github.com/sundowndev/api-js-mooc/
cd api-js-mooc
npm install

Run application

node index.js

Say hello!

curl 127.0.0.1:8080