Skip to content

brangi/NS8-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 

Repository files navigation

NS8-API

Description

API to serve data over RESTful calls for a user tracking software. The server uses lokijs, a in-memory JavaScript Datastore with Persistence.

Install and run the server

Development

npm install
npm run dev

API calls

Firstly, To create users :

POST localhost:4999/signup
{
  "email": "[email protected]",
  "password": "test",
  "phone": "444-333-1111"
}

Login (generate events):

POST localhost:4999/login
{
  "email": "[email protected]",
  "password": "test"
}

Response:

{
  "message": "Created user with email [email protected]"
}
  • Return all events for all users:
GET localhost:4999/events/all

Response:

[
  {
    "type": "LOGIN",
    "created": 1542333383634,
    "user": "[email protected]"
  },
  {
    "type": "LOGIN",
    "created": 1542333385639,
    "user": "[email protected]"
  },
  {
    "type": "LOGIN",
    "created": 1542333386152,
    "user": "[email protected]"
  },
  {
    "type": "LOGIN",
    "created": 1542333431608,
    "user": "[email protected]"
  }
]
  • Return all events for a single user
GET localhost:4999/events/user?[email protected]

Response:

Response:

[
  {
    "type": "LOGIN",
    "created": 1542333903026,
    "user": "[email protected]"
  }
]
  • Return all events for the last day
GET localhost:4999/events/lastday

Response:

[
  {
    "type": "LOGIN",
    "created": 1542333903026,
    "user": "[email protected]"
  },
  {
    "type": "LOGIN",
    "created": 1542333907333,
    "user": "[email protected]"
  },
  {
    "type": "LOGIN",
    "created": 1542333908067,
    "user": "[email protected]"
  }
]

Todo, in the future:

  • Integrate https://jwt.io/ to authorize/authenticate properly
  • Use a persistent database
  • Create test cases
  • Refactor repetitive code specially in the endpoints logic
  • Add ssl for https before deploying on a production server

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published