Skip to content

behlulboluk/nodejs-postgres-sequelize-express

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nodejs Express Rest Api


Config: connectString Postgresql in ./app/config/config.js

Prerequisites

  • postgresql
  • nodejs
  • npm

## install

  • npm install

start

  • npm start

Api usage

Users:

Methods: GET, POST

1. GET

- http://localhost:3000/users

Response - HTTP 200:

{
    "status": "success",
    "message": "Users retrieved",
    "data": [
        {
            "id": 2,
            "name": "Behlül Bahadır Bölük"
        },
        {
            "id": 1,
            "name": "Bahadır Bölük"
        }
    ]
}

2. GET by id

Response - HTTP 200:

{
    "status": "success",
    "message": "Found User",
    "data": {
        "id": 1,
        "name": "Bahadır Bölük",
        "books": {
            "past": [
                {
                    "id": 1,
                    "name": "test 1",
                    "userScore": 9
                },
                {
                    "id": 2,
                    "name": "test 2",
                    "userScore": 6
                }
            ],
            "present": [
                {
                    "id": 3,
                    "name": "test 3"
                }
            ]
        }
    }
}

## 3. POST

Body:

{
    "name": "Behlül Bahadır Bölük"
}

required_fields = ["name"]

Response - HTTP 200:

{
    "status": "success",
    "message": "User created",
    "data": {
        "id": 1,
        "name": "Behlül Bahadır Bölük"
    }
}

## 4. POST - User borrowed a book with userId and bookId

Response - HTTP 204 No Content

5. POST - User returning a book with his score

Body:(Optional)

{
    "score": 9
}

Response - HTTP 204 No content

## Books:

Methods: GET, POST

1. GET

- http://localhost:3000/books

Response - HTTP 200:

{
    "status": "success",
    "message": "Books retrieved",
    "data": [
        {
            "id": 1,
            "name": "test 1"
        },
        {
            "id": 2,
            "name": "test 2"
        },
        {
            "id": 3,
            "name": "test 3"
        }
    ]
}}

2. GET by id

Response - HTTP 200:

{
    "status": "success",
    "message": "Found Book",
    "data": {
        "id": 1,
        "name": "test 1",
        "score": 7.75
    }
}
  • Getting a book which is not scored yet
{
    "status": "success",
    "message": "Found Book",
    "data": {
        "id": 1,
        "name": "test 1",
        "score": -1
    }
}

## 3. POST

Body:

{
    "name": "test 3"
}

required_fields = ["name"]

Response - HTTP 200:

{
    "status": "success",
    "message": "Book created",
    "data": {
        "id": 3,
        "name": "test 3"
    }
}

About

No description or website provided.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published