KUMachine / express-demo-api

simple express project, that consist of an API for users who can post articles, it also contains authentication using JsonWebToken, and built with MongoDB/Mongoose, and MVC design pattern

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Express API Demo

Simple Express API, built with MongoDB/Mongoose

Installation

Use the package manager npm to install Demo app.

npm install

NOTE

Check /config/env/development.js to Make sure the database url is valid.


(Optional)You can use seeder command to seed the database. this will generate a two users with one article for each of them:

npm run seed

To run the server:

npm start

To run the development server: This will reset the server everytime you edit the js files

npm run dev

Usage

when the server is running you can request this endpoints

NOTE

This app has no front-end, so you can only access it through http requests, tools like Postman is prefered to use.

User Routes

GET /api/users
GET /api/users/:userId
GET /api/users/me           #(auth required)current user
POST /api/users
PUT /api/users/:userId      #(auth required)
DELETE /api/users/:userId   #(auth required)

Article Routes

GET /api/articles
GET /api/articles/:articleId
POST /api/articles              #(auth required)
PUT /api/articles/:articleId    #(auth required)
DELETE /api/articles/:articleId #(auth required)

Auth Routes

POST /api/login
POST /api/signup

Middleware

this middleware is used to check if user is authenticated on not

isAuthorized

About

This app contains User and Article models, you can signup through /api/signup to create a user, and login through /api/login to authenticate and post new articles. when you login the api does two things:

  • returns JWT token
  • automaticaly creates a cookie with the same token

the cookie will help you authenticate your subsequent requests if you are in a browser or any other tools like Postman, however you can use the token to authenticate by sending the token through Authorization http header if you are not using cookies.

License

MIT

About

simple express project, that consist of an API for users who can post articles, it also contains authentication using JsonWebToken, and built with MongoDB/Mongoose, and MVC design pattern


Languages

Language:JavaScript 100.0%