Code Monkey home page Code Monkey logo

messaging-api's Introduction

Messing System API

This project is an example of implementation of a Messing System API with nodejs v14.15.3 and MongoDB

Getting started

Install nodejs and mongodb in your machine.

Install dependencies with npm and run the application:

npm install
npm run start

Requirements

Configuration File

You need to create .env file in the root of the project.
Before run the server set your nodejs environment variables

.env

# env example #
NODE_ENV = <NODE_ENV>
PORT = 5000
MONGO_URI = <MONGO_URI>
JWT_SECRET = <JWT_SECRET>
JWT_EXPIRESIN = 3d

API

Server url is https://kasa-messaging-api.herokuapp.com, and it expose the following APIs:

Users routes

  • POST - /ap/users/register - Register a new user

    • email - string
    • name - string
    • password - string
  • POST - /ap/users//login - Login user

    • email - string
    • password - string
  • GET - /api/users - Returns all users (must be logged in)

  • GET - /api/users/:id - Returns user by id (must be logged in)

  • PUT - /api/users/:id - Update user info

    • name - string
    • email - string
    • password - string
  • DELETE - /api/users/:id - Delete user


Messages routes

  • POST - /ap/messages - Create a new message

    • receiver - string
    • message - string
    • subject - string
  • GET - /api/messages - Get all meesages for login user

  • GET - /api/messages/unread - Get all unread messages for user

  • PUT - /api/messages/:meesageId/read - Read message

  • DELETE - /api/messages/:id - Delete message

Postman

You can find a postman requests Docs with examples of how to user this API here

JWT strategy

This project use JSON Web Token (JWT) Bearer Token authentication . The login API returns an access_token that you have to use to send a correct authorization header in calls that require authentication. You can find an example with postman here

Login response:

{
   ...
  "data": {
    ...
      "token": {
          "expires_in": "3d",
          "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...._DkYJJh4s"
      },
  ...
}

Authorization header example:


 Authorization โ†’ Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...._DkYJJh4s

Security

The project implements some of nodejs security techniques:

  • Helmet : can help protect our app from some well-known web vulnerabilities by setting HTTP headers appropriately
  • Express Rate Limit: to protect our applications from brute-force attacks
    • In the server.js we can set a limit of requests in a time window (default is 100 requests in 15 minutes for all endpoints, and 3 requests in a 1 hour for sign up endpoint)

Contributing

If you want to contribute to this starter, consider:

  • Reporting bugs and errors
  • Improve the documentation
  • Creating new features and pull requests

Copyright

Licensed under the MIT license.

messaging-api's People

Contributors

dk169 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.