Coder Social home page Coder Social logo

rest-api-with-node's Introduction

REST-API-with-Node

In this project, we will create a REST API to perform CRUD operations using Node framework, express. The API will perform actions like creating, updating, deleting and reading different todos available in the database.

  • For query building, knex is used.
  • This node app has endpoints:
    • GET /todos - to get all the todos.
    • GET /todos/:id - to get a single todo.
    • POST /todos - to add a new todo.
    • PUT /todos/:id - to update a todo.
    • DELETE /todos/:id - to delete a todo.

I have used knex for query building and execution with postgres as the database.

Directory Structure

REST-API-with-Node

  • routes consist of different end points for request

  • controllers are responsible for handling the request-response cycle

  • services are reponsible for handling the business logic

  • models deal with data in the database

  • middlewares for handling errors if the routes or URLs donot match

  • The flow of the request is as below.

    • A client requests the server for a resource.
    • The routes in the server are matched with the request.
    • The controller is called with the request and response objects, It calls the service.
    • The service calls the model to perform the database operations.
    • The model performs the database operations and returns the result to the service then the flow is reversed till the response is sent to the client.

The request-response cycle follows below order.

index.js => routes => controllers => services => models

Testing the API with thunderclient

  1. Making GET request at <ipaddress>:<port>/todo endpoint.

  1. Making POST request at <ipaddress>:<port>/todo endpoint.

rest-api-with-node's People

Contributors

bijay-05 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.