Simple Express API, built with MongoDB/Mongoose
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
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.
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)
GET /api/articles
GET /api/articles/:articleId
POST /api/articles #(auth required)
PUT /api/articles/:articleId #(auth required)
DELETE /api/articles/:articleId #(auth required)
POST /api/login
POST /api/signup
this middleware is used to check if user is authenticated on not
isAuthorized
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.