Skip to content

Rest-API with OpenAPI documentation for TODO-list app with Fastify

Notifications You must be signed in to change notification settings

Mykhailo-Sichkaruk/TODO-list-API-2.0

Repository files navigation

TODO List Api v2.0

This is a simple TODO list API built with Fastify. It allows basic CRUD operations on a TODO List and Tasks + subscribe User to other's List.


Rewriten TODO list Api v1.0 with new features:

  • Fastify instead of Express
  • Encapsulated functionality with fastify-plugins
  • Less code
  • More readable and modular code

And keeping the old features:

  • TODO List API
  • RESTfull API
  • JWT authentication
  • CRUD operations
  • Prisma ORM
  • PostgreSQL
  • Swagger documentation
  • TypeScript

Table of Contents

Project structure

/*
  [src]
  ├──[plugins] - incapsulated functionality of app and optinos
  ├──[routes]
  │  ├──[auth]
  │  │  │── │handler.ts│ - handlers for login and register
  │  │  │── │index.ts│   - register routes with options
  │  │  │── │options.ts│ - put together handlers and schema
  │  │  └── │chema.ts│   - validation and serialization 
  │  ├──[list]
  │  │  │── │handler.ts│ - CRUD + /subscribe handlers
  │  │  │── │index.ts│   - register routes with options
  │  │  │── │options.ts│ - put together handlers and schema
  │  │  └── │chema.ts│   - validation and serialization 
  │  └──[task]
  │     │── │handler.ts│ - CRUD handlers
  │     │── │index.ts│   - register routes with options
  │     │── │options.ts│ - put together handlers and schema
  │     └── │chema.ts│   - validation and serialization 

  │──│server.ts│ - set options, register plugins, routes
  └──│app.ts│ - import and start server
  --------------------------------------------------------
  [test]
  └──│index.ts│ - start all tests
  
*/

Prerequirements

Installation

  • Download repo
git clone https://github.com/Mykhailo-Sichkaruk/TODO-list-api
  • Change directory to downloaded repo
cd TODO-list-api
  • Install dependencies:
npm install
  • Setup Postgres
    • Open .env file in project root
    • Set your password and login for postgress in DATABASE_URL to postgres://_YOUR_POSTRGES_LOGIN_:_YOUR_POSTGRES_PASSWORD_@localhost:5432/mydb?schema=public (Without '_' symbols)
    • It shold be like this: DATABASE_URL="postgres://postgres:todo@localhost:5432/mydb?schema=public"
  • Run server:
npm start 
  • Follow instrunction in terminal

Authentication

  • Click Register register
  • Click Try it out registe-ty-it-out
  • Clisk Execute register-execute
  • Copy token fron response`s header or body copy-token
  • Scroll up and click Autorize click-autorize
  • Paste token paste-token and clisck Autorize

Great You added token to header!

API

Read detailed about API in Swagger/Open API docs

Autentication

  • Sign up with login and password (POST /auth/register)
  • Sign in with login and password (POST /auth/login)

List managment

  • List has
    • title (string)
    • subscribers (array Users)
    • author (string)
    • tasks (array of strings)
  • Create list (POST /list)
  • Get list (GET /list/)
  • Get all lists (GET /list)
  • Update list (PUT /list)
  • Delete list (DELETE /list)

Task managment

  • Task has
    • id
    • title
    • body
    • status (ACTIVE or IN_PROGRES or DONE or CLOSED)
    • listId
    • deadline
    • authorId
  • Create task (POST /task)
  • Get task (GET /task/)
  • Get all tasks (GET /task)
  • Update task (PUT /task)
  • Delete task (DELETE /task)

Scbscribe user to list

  • Subscribe user to list (POST /list/subscribe)

Tech details

  • Database: Postgres
  • ORM: Prisma
  • Language: TypeScript
  • Execution environment: Node.js
  • Framework: Fastify
  • Documentation: Swagger/Open API

About

Rest-API with OpenAPI documentation for TODO-list app with Fastify

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published