montenegroleticia / Workout-api

This is a API of a gym training library designed to be a POC of typescript and CRUD operations.

Home Page:https://workout-api-t8nm.onrender.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Workout Library API

The API is a library of gym training exercises with name, type, and description.

Designed to be a POC (Proof of Concept), this is a functional API made with Node.js to showcase TypeScript concepts with Express and SQL, developing integrated CRUD operations like POST, GET, PUT, and DELETE routers.

Technologies Used

Node.jstypescriptExpress.jsPostgreSQLPrisma

API Documentation

POST /workouts

Create a new training exercise.

URL: https://workout-api-t8nm.onrender.com/workouts

Method: POST

Request Parameters:

Parameter Type Description
name string Name of the exercise
type string Type of the exercise
description string Description of the exercise

Request Example:

POST /workouts Content-Type: application/json

{
  "name": "Squat",
  "type": "Legs",
  "description": "Exercise for strengthening leg muscles."
}

Status: 201 Created Content-Type: application/json

{
  "id": 1,
  "name": "Squat",
  "type": "Legs",
  "description": "Exercise for strengthening leg muscles."
}
GET /workouts

Get the list of all training exercises.

URL: https://workout-api-t8nm.onrender.com/workouts

Method: GET

Response Example:

Status: 200 OK Content-Type: application/json

[
  {
    "id": 1,
    "name": "Squat",
    "type": "Legs",
    "description": "Exercise for strengthening leg muscles."
  },
  {
    "id": 2,
    "name": "Bench Press",
    "type": "Chest",
    "description": "Exercise for strengthening chest muscles."
  },
  ...
]
GET by id /workouts:id

Get one training exercise.

URL: https://workout-api-t8nm.onrender.com/workouts/:id

Method: GET

Response Example:

GET /workouts/1 Content-Type: application/json

{
  "id": 1,
  "name": "Squat",
  "type": "Legs",
  "description": "Exercise for strengthening leg muscles."
}

PUT /workouts/:id

Update an existing training exercise.

URL: https://workout-api-t8nm.onrender.com/workouts/:id

Method: PUT

Request Parameters:

Parameter Type Description
name string Updated name of the exercise
type string Updated type of the exercise
description string Updated description of the exercise

Request Example:

PUT /workouts/1 Content-Type: application/json

{
  "name": "Free Squat",
  "type": "Legs",
  "description": "Exercise for strengthening leg muscles."
}

Response Example:

Status: 200 OK Content-Type: application/json

{
  "id": 1,
  "name": "Free Squat",
  "type": "Legs",
  "description": "Exercise for strengthening leg muscles."
}    

DELETE /workouts/:id

Delete a training exercise.

URL: https://workout-api-t8nm.onrender.com/workouts/:id

Method: DELETE

Request Parameters:

Parameter Type Description
id number ID of the exercise to delete

Request Example:

DELETE /workouts/1

Response Example:

Status: 204 No Content

How to run

  1. Clone this repository:
    https://github.com/montenegroleticia/Workout-api.git
  1. Install dependencies:
npm i
  1. Run Prisma:
npm i -D prisma
npx prisma init
  1. Adjust .env
  2. Generate the model through the bank:
npx prisma db pull
  1. Create the migration and manage the Prisma Client:
npx prisma migrate dev
  1. Create Seed:
npm run seed
  1. Run the API with:
npm run dev
  1. Finally, access it in your preferred browser or use Thunder Client or similar:
http://localhost:5000

About

This is a API of a gym training library designed to be a POC of typescript and CRUD operations.

https://workout-api-t8nm.onrender.com


Languages

Language:TypeScript 100.0%