Skip to content

hericles-koelher/dart_rest_api

Repository files navigation

A simple REST API made using the dart language.

Repository size GitHub last commit License made by Hericles Koelher

Status: Finished

AboutFeaturesHow it worksTech StackAuthorLicense


About

Dart REST API is just an little project made with the purpose of study back-end development with Dart.


Features

  • User register
  • User auth with JsonWebToken
  • User account update
  • User account delete
  • CRUD operations with Expressions
  • Only logged users have authorization to access data from "expressions" endpoint

How it works

This API has only two endpoints:

  • Auth
  • Expressions

Note: To realize actions as an authenticated user the request header must have the field "Authorization" with the following value "Bearer {accessToken}", where {accessToken} should be replaced with your auth token.

Endpoint /auth


This endpoint handle all actions related to an user:

  • Register
  • Login/Logout
  • Update Info
  • Delete Account

[POST] /auth/register

Description: Register an user on system. On success, returns an answer with status code 201 and a string with a success message. In case this process fail, then returns an answer with status 4XX and a string with a better description of the problem.

Examples:

  • Request address:

    http://localhost:8080/auth/register
  • Request body::

    {
      "username" : "Dobby",
      "email" : "[email protected]",
      "password" : "#FreeElves"
    }
  • Answer:

    User successfully registered
    

[POST] /auth/login

Description: Performs the user login on system. On success, returns an answer with status code 200 and a JSON with two 'tokens', being one for auth (expires in 15 minutes) and the other to renew the first one (expires in 30 minutes). In case this process fail, then returns an answer with status 4XX and a string with a better description of the problem.

Examples:

  • Request address:

    http://localhost:8080/auth/login
  • Request body:

    {
      "email" : "[email protected]",
      "password" : "#FreeElves"
    }
  • Answer:

    {
      "token" : "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE2NDI3NzEzMDYsImV4cCI6MTY0Mjc3MzEwNiwic3ViIjoiMSIsImlzcyI6ImxvY2FsaG9zdCIsImp0aSI6IjA2ZmVhZmI5LTA4MTEtNGRhZS05YTljLTc5NjBmNzVlYTZhMSJ9.76LagMOKPVgY0-ZScMDhlRjpwvbXESqUCGDhbbPPbQQ",
      "refreshToken" : "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE2NDI3NzEzMDYsImV4cCI6MTY0Mjc3NDkwNiwic3ViIjoiMSIsImlzcyI6ImxvY2FsaG9zdCIsImp0aSI6IjA2ZmVhZmI5LTA4MTEtNGRhZS05YTljLTc5NjBmNzVlYTZhMSJ9.A4YkORrXTZOjnANhisPRSAED_PLgLTA6biIVkSz11pk"
    }

[POST] /auth/refreshToken

Description: Renew an user token on system. On success, returns an answer with status code 200 and a JSON with two 'tokens', being one for auth (expires in 15 minutes) and the other to renew the first one (expires in 30 minutes). In case this process fail, then returns an answer with status 4XX and a string with a better description of the problem.

Examples:

  • Request address:

    http://localhost:8080/auth/refreshToken
  • Request body:

    {
      "refreshToken" : "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE2NDI3NzEzMDYsImV4cCI6MTY0Mjc3NDkwNiwic3ViIjoiMSIsImlzcyI6ImxvY2FsaG9zdCIsImp0aSI6IjA2ZmVhZmI5LTA4MTEtNGRhZS05YTljLTc5NjBmNzVlYTZhMSJ9.A4YkORrXTZOjnANhisPRSAED_PLgLTA6biIVkSz11pk"
    }
  • Answer:

    {
      "token" : "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE2NDI3NzI1MDMsImV4cCI6MTY0Mjc3NDMwMywic3ViIjoiMSIsImlzcyI6ImxvY2FsaG9zdCIsImp0aSI6Ijc0ODYyMzUzLWQwZmUtNDk4OC1iOWQwLWZiN2YyNTJhZjI3YyJ9.QEqezAmz333iQNVpsWG6UZUidLDOKHgx2KWyc-lW9KI",
      "refreshToken" : "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpYXQiOjE2NDI3NzI1MDMsImV4cCI6MTY0Mjc3NjEwMywic3ViIjoiMSIsImlzcyI6ImxvY2FsaG9zdCIsImp0aSI6Ijc0ODYyMzUzLWQwZmUtNDk4OC1iOWQwLWZiN2YyNTJhZjI3YyJ9.SjmSc23465l35-kJQneEfFe8mTohv9G9FSiZ0-2oFIM"
    }

[POST] /auth/logout

Description: Performs an user logout on system and revoke their renew token. On success, returns an answer with status code 200 and a string with a success message. In case this process fail, then returns an answer with status 4XX and a string with a better description of the problem (probably unauthorized user exception).

Examples:

  • Request address:

    http://localhost:8080/auth/logout
  • Answer:

    Successfully logged out
    

[PUT] /auth/updateInfo

Description: Updates an user info on system. On success, returns an answer with status code 200 and a string with a success message. In case this process fail, then returns an answer with status 4XX and a string with a better description of the problem.

Examples:

  • Request address:

    http://localhost:8080/auth/updateInfo
  • Request body:

    {
      "username" : "Free Dobby",
      "email" : "[email protected]",
      "password" : "ThanksHarry"
    }
  • Answer

    User information successfully updated
    

[DELETE] /auth/deleteAccount

Description: Deletes an user on system and revokes their renew token. On success, returns an answer with status code 200 and a string with a success message. In case this process fail, then returns an answer with status 4XX and a string with a better description of the problem (probably unauthenticated user exception).

Examples:

  • Request address:

    http://localhost:8080/auth/deleteAccount
  • Answer:

    User successfully deleted
    

Endpoint /expressions


This endpoint make it possible to an authenticated user perform CRUD operations on Expressions.


[POST] /expressions

Description: Creates an expression on system. On success, returns an answer with status code 201 and a JSON with the created expression. In case this process fail, then returns an answer with status 4XX and a string with a better description of the problem.

Examples:

  • Request address:

    http://localhost:8080/expressions
  • Request body::

    {
      "expression" : "Go on a wild goose chase",
      "meaning" : "To do something pointless"
    }
  • Answer:

    {
      "id" : 1,
      "expression" : "Go on a wild goose chase",
      "meaning" : "To do something pointless",
      "lastUpdate" : "2022-01-21T13:58:06.578517"
    }

[GET] /expressions

Description: Get all expressions on system. On success, returns an answer with status code 200 and a JSON with a list of expressions. In case this process fail, then returns an answer with status 4XX and a string with a better description of the problem.

Examples:

  • Request address:

    http://localhost:8080/expressions
  • Answer:

    [
      {
      "id" : 0,
      "expression" : "Get a taste of your own medicine",
      "meaning" : "Get treated the way you've been treating others (negative)",
      "lastUpdate" : "2022-01-19T19:34:09.244124"
      },
      {
      "id" : 1,
      "expression" : "Go on a wild goose chase",
      "meaning" : "To do something pointless",
      "lastUpdate" : "2022-01-21T13:58:06.578517"
      }
    ]

[GET] /expressions/{id}

Description: Get an expression on system. On success, returns an answer with status code 200 and a JSON with the referred expression. In case this process fail, then returns an answer with status 4XX and a string with a better description of the problem.

Examples:

  • Request address:

    http://localhost:8080/expressions/1
  • Answer:

    {
      "id" : 1,
      "expression" : "Go on a wild goose chase",
      "meaning" : "To do something pointless",
      "lastUpdate" : "2022-01-21T13:58:06.578517"
    }

[PUT] /expressions/{id}

Description: Updates an expression on system. On success, returns an answer with status code 200 and a JSON with the updated expression. In case this process fail, then returns an answer with status 4XX and a string with a better description of the problem.

Examples:

  • Request address:

    http://localhost:8080/expressions/1
  • Request body::

    {
      "expression" : "Go on a wild goose chase",
      "meaning" : "Bla bla bla",
    }
  • Answer:

    {
      "id" : 1,
      "expression" : "Go on a wild goose chase",
      "meaning" : "Bla bla bla",
      "lastUpdate" : "2022-01-21T13:59:06.384333"
    }

[DELETE] /expressions/{id}

Description: Deletes an expression on system. On success, returns an answer with status code 204. In case this process fail, then returns an answer with status 4XX and a string with a better description of the problem.

Examples:

  • Request address:

    http://localhost:8080/expressions/1

Pre-requisites

Before you begin, you will need to have Docker installed and configured in your machine.

Running the application

From the root folder run docker-compose and create the necessary containers.

$ docker-compose up -d

Tech Stack

The following tools were used in the construction of the project:

Mobile

Utilities


Author

Hericles Koelher
Hericles Koelher

Twitter Badge Linkedin Badge


License

This project is under the license MIT.

Made with love by Hericles Koelher

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published