Coder Social home page Coder Social logo

nodejs-restful-api-express's Introduction

nodejs-restful-api-express

RESTful API made with Node.js where a registered user can list, create, update or delete courses that are stored in a database. It will be needed a token, which will be received when you log in.

Getting Started

Prerequisites

  • MongoDB
  • Redis
  • Node.js
  • NPM / Yarn

Installing

  • Clone the repository: https://github.com/kazordoon/nodejs-restful-api-express.git
  • Get in the project directory: cd nodejs-restful-api-express
  • Install the dependencies:
    • NPM: npm i | Remove the file yarn.lock before installing with NPM
    • Yarn: yarn

Setting environment variables

Copy the .env.example file to the .env, then you will need to set the variable values into the .env file according to your environment.

Running the server

  • NPM: npm run dev
  • Yarn: yarn dev

API endpoints

Users

Action Path Body Method Returns
Create a new user /auth/register A JSON with these fields POST A JSON with a token
Login into an account /auth/login A JSON with these fields POST A JSON with a token

Courses

Action Path Parameters Body Method Returns
List all courses /courses -- -- GET All courses
List one course /courses/{id} id -- GET The course that has the same id as the one found in the id parameter
Create a new course /courses - A JSON with these fields POST The created course
Update a existing course /courses/{id} id A JSON with at least one of these fields PATCH The updated course
Delete a course /courses/{id} id -- DELETE --

How to use the token

You need to put the token on the authorization header.

Input data validation

user-fields

  • username
    • Type: string
    • Minimium characters: 3
    • Maximium characters: 20
  • password
    • Type: string
    • Minimium characters: 8
    • Maximium characters: 50

course-fields

  • name:
    • Type: string
    • Minimium characters: 5
    • Maximium characters: 50
  • description
    • Type: string
    • Minimium characters: 15
    • Maximium characters: 100
  • workload
    • Type: number
    • Minimium: 1
  • total_classes
    • Type: number
    • Minimum: 1
  • year
    • Type: number
    • Minimum: 1970
    • Maximum: <current_year>

Examples

See the EXAMPLES.md.

Built With

  • Node.js - JavaScript runtime environment that executes JavaScript code server-side
  • MongoDB - NoSQL Database
  • mongoose - MongoDB object modeling tool
  • express - Minimalist web framework for Node.js
  • consign - Autoload for the scripts
  • cors Node.js CORS middleware
  • express-validator - Data input validator
  • bcryptjs - A library to help you hash passwords
  • jsonwebtoken - An implementation of JSON Web Tokens
  • ioredis - A robust, performance-focused and full-featured Redis client for Node.js

Versioning

For the versions available, see the tags on this repository.

Authors

License

This project is licensed under the MIT License - see the LICENSE file for details

nodejs-restful-api-express's People

Contributors

dependabot[bot] avatar kazordoon avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

nodejs-restful-api-express's Issues

Gafanhoto

E aí, ví teu perfil no post do Guanabra !! A quanto tempo você programa ?

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.