Express REST API example
 
Go to file
Raphael Cerveaux 03701bc0de
Merge pull request #9 from sundowndev/develop
v1.0.0 release
2018-11-17 12:12:35 +01:00
app Account update bugfix 2018-11-17 01:01:52 +01:00
config JWT secret 2018-11-15 19:29:35 +01:00
docs API docs 2018-11-17 01:01:35 +01:00
.eslintignore Install eslint 2018-11-13 11:15:47 +01:00
.eslintrc.json ESlint cfg 2018-11-17 00:43:22 +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 Fix Eslint errors 2018-11-16 12:28:37 +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-16 18:18:46 +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