Skip to content

Instantly share code, notes, and snippets.

@williamn
Created December 8, 2017 05:30
Show Gist options
  • Save williamn/57a41d41d531ab7ed2ee7d7b87c8f421 to your computer and use it in GitHub Desktop.
Save williamn/57a41d41d531ab7ed2ee7d7b87c8f421 to your computer and use it in GitHub Desktop.
Notejam API

Notejam API

Application overview

Inspired by komarserjio/notejam

Notejam is a web application which allows user to sign up/in/out and create/view/edit/delete notes. Notes are grouped in pads. There will 2 part of the application. First is the backend which is provide HTTP API for the second part: the frontend which handles the UI.

Task overview

Your task is to build the HTTP API application. We will name it: Notejam API.

Objects/Models/Entities

Structure of objects (aka models or entities) used in the app:

  • Note: id, pad_id, user_id, name, text, created_at, updated_at
  • Pad: id, user_id, name
  • User: id, email, password

See recommended "data"base schema for details.

Endpoints

All responses must be encoded in JSON and have the appropriate Content-Type header and HTTP status code.

Content-Type: "application/json"

Note

Create note

POST /notes/create

{
    "pad_id": 1,
    "user_id": 1,
    "name": "Hello, World!"
    "text": "Lorem ipsum"
}
Attribute Description
pad_id Pad ID
user_id User ID
name Note title/name
text Note body

Returns:

{
    "data": [
        {
            "id": 1,
            "pad_id": 1,
            "user_id": 1,
            "name": "Hello, World!",
            "text": "Lorem ipsum"
        }
    ]
}
Error Description
400 any required attribute is not present
409 The desired name is already in use by the user_id

View note

GET /notes/<note_id>

Returns:

{
    "data": [
        {
            "id": 1,
            "pad_id": 1,
            "user_id": 1,
            "name": "Hello, World!",
            "text": "Lorem ipsum"
        }
    ]
}
Error Description
404 The desired note_id is not found

Edit note

PUT /notes/<note_id>

{
    "pad_id": 1,
    "user_id": 1,
    "name": "Hello, World!"
    "text": "Lorem ipsum"
}

Returns:

{
    "data": [
        {
            "id": 1,
            "pad_id": 1,
            "user_id": 1,
            "name": "Hello, World!",
            "text": "Lorem ipsum"
        }
    ]
}
Error Description
404 The desired note_id is not found
400 any required attribute is not present

Delete note

DELETE /notes/<note_id>

Returns:

{
    "data": null
}
Error Description
404 The desired note_id is not found

Pad

Create pad

POST /pads/create

{
    "user_id": 1,
    "name": "General"
}
Attribute Description
user_id User ID
name Pad title/name

Returns:

{
    "data": [
        {
            "id": 1,
            "user_id": 1,
            "name": "General"
        }
    ]
}
Error Description
400 any required attribute is not present
409 The desired name is already in use by the user_id

View pad

GET /pads/<pad_id>

Returns:

{
    "data": [
        {
            "id": 1,
            "user_id": 1,
            "name": "General"
        }
    ]
}
Error Description
404 The desired pad_id is not found

Edit pad

PUT /pads/<pad_id>

{
    "user_id": 1,
    "name": "General"
}

Returns:

{
    "data": [
        {
            "id": 1,
            "user_id": 1,
            "name": "General"
        }
    ]
}
Error Description
404 The desired pad_id is not found
400 any required attribute is not present

Delete pad

DELETE /pads/<pad_id>

Returns:

{
    "data": null
}
Error Description
404 The desired pad_id is not found

Functional/unit tests

Any kind of tests are very desirable.

Recommended test cases

Notes

  • Note can be successfully created
  • Note can't be created if required fields are missing
  • Note can't be edited if required fields are missing
  • Note can be successfully deleted

Pads

  • Pad can be successfully created
  • Pad can't be created if required fields are missing
  • Pad can't be edited if required fields are missing
  • Pad can be successfully deleted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment