Skip to content

CoryKoehler/refactoredtypescriptapi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Refer to Readmecontinued.md Disclaimer - was given incorrectly as a starting place with the 4 task below that I never finished, and this code should never be used seriously, providing it online for sharing purposes as a pseudo kata

This came from the below git hubs and the refactoring was just a pseudo kata for myself

  • V1.0.0: you can run the server directly after cloning this version. It will create a simple RESTful API over HTTP.
  • V2.0.0: this is a more secure and control API project. You need to read the post on how to secure RESTful API application first. After that, you can run the project.

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

Contributors 3

  •  
  •  
  •