Giter Club home page Giter Club logo

crud-api's Introduction

CRUD API

Install dependencies

npm install

Run app in development mode(nodemom/ts-node)

npm run start:dev

PORT=5000 or it can be changed in .env

Npm start multiple instances of app

npm run start:multi

Build app in production mode(webpack/ts-loader) and run app

npm run start:prod

Run the tests(jest/supertest)

npm run test

Get all users

Request

GET /api/users

Response

status code 200 and all users records

Create a new user

Request

POST /api/users

body: { username — user's name (string, required) age — user's age (number, required) hobbies — user's hobbies (array of strings or empty array, required) }

example {"username": "Andrey", "age":20, hobbies: []}

Response

status code 201 and newly created record

body {"id":"uuid","username":"Andrey","age":20, hobbies: []}

status code 400 and corresponding message if request body does not contain required fields or fields are invalid

body 'Body does not contain required fields'

Get a specific user by id

Request

GET /api/users/${userId}

userId - valid uuid identifier

Response

status code 200 and newly created record

{"id":"f8ccd33f-f817-4f09-89e1-99fdfde62157","username":"SomeName","age": 45, hobbies: ['flex']}

status code 400 and corresponding message if userId is invalid (not uuid)

User id ${idFromReq} is invalid

status code 404 and corresponding message if record with id === userId doesn't exist

User with id ${idFromReq} does not exist

Update a specific user by id(can update all or some fields)

Request

PUT /api/users/${userId}

userId - valid uuid identifier

Response

status code 200 and updated record

{"id":"f8ccd33f-f817-4f09-89e1-99fdfde62157","username":"NewName", "age": 15, hobbies: ["reading"]}

status code 400 and corresponding message if userId is invalid (not uuid)

Body User id ${idFromReq} is invalid

status code 400 and corresponding message if request body does not contain required fields or fields are invalid

Body Body does not contain required fields

status code 404 and corresponding message if record with id === userId doesn't exist

Body User with id ${idFromReq} does not exist

Delete a specific user by id

Request

DELETE /api/users/${userId}

userId - valid uuid identifier

Response

status code 204 if the record is found and deleted

status code 400 and corresponding message if userId is invalid (not uuid)

body User id ${idFromReq} is invalid

status code 404 and corresponding message if record with id === userId doesn't exist

body User with id ${idFromReq} does not exist

Other errors

status code 500

'Internal Server Error'

crud-api's People

Contributors

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