Skip to content

afranca/api-pol-ts

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pre-requisites

  • nodejs installed (prefereably version 16, eg.: v16.13.2)
  • npm installed (should be come with nodejs installation)
  • postman installed
  • port 3000 available on localhost

How to run the API

  • Clone the repo: git clone [email protected]:afranca/api-pol-ts.git
  • Navigate into the api-pol-ts dir: cd api-pol-ts
  • Download project dependencies: npm install
  • Compile typescript code: tsc or tsc -w
  • Start the server: npm start
  • Execute a GET request on postman: http://localhost:3000/api/users

API Description

POST /api/user

  • Request Body: { "name": "user 3", "age": 100, "occupation": "lifter", "role": "head" }
  • Responses:
    • Success:
      • status: 200
      • body:
        { "message": "Successfully created.", "entry": { "id": "0.09783725362257334", "type": "poweruser", "name": "user 3", "age": 100, "role": "head", "occupation": "lifter" } }
    • Failure:
      • status: 500
      • body:
        { "message": [ERROR MESSAGE] }

GET /api/user/:id

  • example: http://localhost:3000/api/users/0.09783725362257334
  • Response:
    • Success:
      • status: 200
      • body:
        { "message": "Successfully created.", "entry": { "id": "0.09783725362257334", "type": "poweruser", "name": "user 3", "age": 100, "role": "head", "occupation": "lifter" } }
    • Failure:
      • status: 500
      • body:
        { "message": [ERROR MESSAGE] }

New Blank Project (only if you are creating project from scratch)

init npm & typescript project

npm init tsc --init

Production dependencies

npm install --save express body-parser

Dev dependencies

  • npm install --save-dev nodemon
  • npm install --save-dev @types/node
  • npm install --save-dev @types/express

About

API using Typescript & Express

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors