Code Monkey home page Code Monkey logo

diary's Introduction

This is the backend application which enables users to perform CRUD operations on the notes. A note is a simple data structure which consists of a title, body and a few other fields. The app is built in the style of a RESTful API that enables devs to plug in multiple clients in their favorite language/framework/stack (browser, mobile, desktop etc..)

The app has no integration tests because I have a full time job.. LOL (might add them later though)


Below you will see the typical flow of the app usage:

  1. User registration
    • User registers with email and password
    • User email must be unique
  2. User login
    • User must log in to get back a JSON Web Token (JWT)
    • JWT will be used for accessing protected routes
  3. Display User notes
    • User can fetch all notes which he/she has ever created/updated
  4. Create new User note
    • User can create a new note with specified title and body
  5. Modify/Delete existing User notes
    • User can change the fields of the specific note, or delete it at all
  6. Search/Sort User notes
    • User can apply exact/non-exact searching and ascending/desending sorting to his/her notes

Let's discuss step by step what each step does and how the HTTP Request/Response, API Endpoint and related things look like:


  1. User registration

    Endpoint HTTP Method Content Type HTTP Success (Statuscode) HTTP Failure (Statuscode)
    http://localhost:8080/api/user/signup POST application/json User has been created (200) User already exists (409)

    Request Body:

    {
      "name": "Nika",
      "email": "[email protected]",
      "password": "my-strong-pass"
    }

  1. User login

    Endpoint HTTP Method Content Type HTTP Success (Statuscode) HTTP Failure (Statuscode)
    http://localhost:8080/api/user/login POST application/json {"token": "JWT"} (200) Auth failed (401)

    Request Body:

    {
      "email": "[email protected]",
      "password": "my-strong-pass"
    }

  1. Display User notes

    Endpoint HTTP Method Content Type HTTP Success (Statuscode) HTTP Failure (Statuscode)
    http://localhost:8080/api/notes GET application/json Notes in JSON format (200) Auth failed (401)
    hint: use the real JWT returend upon the successful login

    Headers:

    Authorization: Bearer JWT
    

    Typical response:

     [
       {
           "id": 7159997665991673534,
           "title": "I love Scala",
           "body": "Scala rocks (most definitely)",
           "createdAt": "09-16-2022"
       },
       {
           "id": 5746959445480553359,
           "title": "I kinda like Java",
           "body": "Java rocks (kinda)",
           "createdAt": "09-16-2022"
       },
       {
           "id": 3672367746746389626,
           "title": "I completely hate Python",
           "body": "Python sucks (yep yep)",
           "createdAt": "09-16-2022"
       }
    ]

  1. Create new Note

    Endpoint HTTP Method Content Type HTTP Success (Statuscode) HTTP Failure (Statuscode)
    http://localhost:8080/api/notes POST application/json Note has been created (200) Auth failed (401)
    hint: use the real JWT returend upon the successful login

    Headers:

    Authorization: Bearer JWT
    

    Request Body:

    {
        "title": "why should I learn ZIO?",
        "body": "cuz [insert 5 million intelligent words here]",
        "createdAt": "17-09-2022"
    }

  1. Get Note by ID

    Endpoint HTTP Method Content Type HTTP Success (Statuscode) HTTP Failure (Statuscode)
    http://localhost:8080/api/notes/:id GET application/json Note in JSON format (200) Auth failed (401) / Note does not exist
    hint: use the real JWT returend upon the successful login

    Headers:

    Authorization: Bearer JWT
    

    Typical Response:

    {
        "id": 5321604607032827422,
        "title": "why should I learn ZIO?",
        "body": "cuz [insert 5 million intelligent words here]",
        "createdAt": "17-09-2022"
    }

  1. Delete Note by ID

    Endpoint HTTP Method Content Type HTTP Success (Statuscode) HTTP Failure (Statuscode)
    http://localhost:8080/api/notes/:id DELETE application/json Note has been deleted (200) Auth failed (401) / Note does not exist
    hint: use the real JWT returend upon the successful login

    Headers:

    Authorization: Bearer JWT
    

  1. Update Note fully

    Endpoint HTTP Method Content Type HTTP Success (Statuscode) HTTP Failure (Statuscode)
    http://localhost:8080/api/notes/:id PUT application/json Note has been updated (200) Auth failed (401) / Note does not exist
    hint: use the real JWT returend upon the successful login

    Headers:

    Authorization: Bearer JWT
    

    Request Body:

    {
       "id": 7043231874327471104,
       "title": "why should I learn ZIO?!?!?!?!?!",
       "body": "cuz [insert 5 million intelligent words here]",
       "createdAt": "17-09-2022"
    }

  1. Search for a specific Note

    Endpoint HTTP Method Content Type HTTP Success (Statuscode) HTTP Failure (Statuscode)
    http://localhost:8080/api/notes/search?title={title} GET application/json Note array in JSON format (200) Auth failed (401)
    hint: use the real JWT returend upon the successful login

    Headers:

    Authorization: Bearer JWT
    

    Typical response:

     [
       {
           "id": 7159997665991673534,
           "title": "I love Scala",
           "body": "Scala rocks (most definitely)",
           "createdAt": "09-16-2022"
       },
       {
           "id": 5746959445480553359,
           "title": "I kinda like Java",
           "body": "Java rocks (kinda)",
           "createdAt": "09-16-2022"
       },
       {
           "id": 3672367746746389626,
           "title": "I completely hate Python",
           "body": "Python sucks (yep yep)",
           "createdAt": "09-16-2022"
       }
    ]

  1. Sort notes by title

    Endpoint HTTP Method Content Type HTTP Success (Statuscode) HTTP Failure (Statuscode)
    http://localhost:8080/api/notes/sort?order=asc GET application/json Note array in JSON format (200) Auth failed (401)
    hint: use the real JWT returend upon the successful login

    Headers:

    Authorization: Bearer JWT
    

    Typical response:

    [
      {
        "id" : 3672367746746389626,
        "title" : "I completely hate Python",
        "body" : "Python sucks (yep yep)",
        "createdAt" : "09-16-2022"
      },
      {
        "id" : 5746959445480553359,
        "title" : "I kinda like Java",
        "body" : "Java rocks (kinda)",
        "createdAt" : "09-16-2022"
      },
      {
        "id" : 7159997665991673534,
        "title" : "I love Scala",
        "body" : "Scala rocks",
        "createdAt" : "09-16-2022"
      },
      {
        "id" : 7043231874327471104,
        "title" : "why should I learn ZIO?",
        "body" : "cuz [insert 5 million intelligent words here]",
        "createdAt" : "17-09-2022"
      }
    ]

diary's People

Contributors

ghurtchu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

thm068

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.