/mock-notes-api

Repository containing raw data for json-server to setup mock API of notes - for classes and presentations

Primary LanguageJavaScript

Mock notes API

This repository contains a mock API created based on db.json file.

I'm using json-server ❤️

API supports 2 version, both operating on the same dataset - one requires authentication, second does not. If you are not sure how to use it - no problem, please read this README carefully to the end 😊

Run it locally

Simply

  • npm install
  • npm start
  • The server by default is visible under localhost:3030

Routes

Open

No prefixes, just go to url, f.e.: GET ~/notes

v2 Auth required

Under version 2, use v2 prefix, f.e.: GET ~/v2/notes

Login

Simple demo authorization supports only one user - Mr/Mrs/Miss Admin Admin. In response you will get JWT bearer token, always this hardcoded one.

Request

POST ~/v2/login

payload:

{
    "username": "admin",
    "password": "admin"
}

headers:

content-type: application/json`

Response

  • success
200

{
    "name": "Admin Admin",
    "token": {the token}
}
  • failure (no credentials or wrong credentials)
400

Making calls to v2

Add Authorization header with bearer token

Example:

HEADERS:
Authorization: Bearer eyJ0eXA...