Coder Social home page Coder Social logo

node-crud-api's Introduction

Simple CRUD API

Implement simple CRUD API using in-memory database underneath.


Installation

$ git clone https://github.com/shopot/node-crud-api.git
$ cd node-crud-api
$ git checkout develop
$ npm install

Configuration

Rename the file .env.example to .env for set load and set PORT environment variable from .env file.

Running the app

Start development server:

$ npm run start:dev

Build and start production server:

$ npm run start:prod

Start development server with Cluster API and balancing:

$ npm run start:dev:multi

Build and start production server with Cluster API and balancing:

$ npm run start:prod:multi

Run end-to-end (e2e) API test:

You must stop all production or development server before run tests

$ npm run test

OpenAPI docs

https://nodejs-crud-openapi.netlify.app/


Endpoints description

  • GET api/users is used to get all persons
    • Response: status code 200 and all users records
  • GET api/users/${userId}
    • Response: status code 200 and and record with id === userId if it exists
    • Response: status code 400 and message Invalid user id if provided id is not valid uuid
    • Response: status code 404 and message User not found
  • POST api/users is used to create record about new user and store it in database
    • Response: status code 201 and newly created record
    • Response: status code 400 and message Bad request if request body does not contain required fields
  • PUT api/users/{userId} is used to update existing user
    • Response: status code 200 and updated record
    • Response: status code 400 and message Invalid user id if provided id is not valid uuid
    • Response: status code 404 and and message User not found
  • DELETE api/users/${userId} is used to delete existing user from database
    • Response: status code 204 if the record is found and deleted
    • Response: status code 400 and message Invalid user id if provided id is not valid uuid
    • Response: status code 404 and and message User not found

Requests to non-existing endpoints (e.g. some-non/existing/resource) Response: status code 404 Not found)


Testing

Script npm run test runs end-to-end test for all HTTP Request (GET, CREATE, PUT, DELETE) methods with valid and invalid data.

node-crud-api's People

Contributors

shopot 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.