Skip to content

Latest commit

 

History

History
177 lines (135 loc) · 3.25 KB

README.md

File metadata and controls

177 lines (135 loc) · 3.25 KB

Acronym API

Description

This is a simple API that allows you to create, read, update and delete acronyms.

Installation

  1. Install the dependencies

     npm install
    
    or
    yarn
    
    or
    pnpm install
  2. Create a .env file in the root directory and add the following environment variables:

    DATABASE_URL="YOUR_DATABASE_URL" # Note: This uses mongodb as the database, however you can modify the code to use any database of your choice
  3. Run the Prisma commands to generate the Prisma client and migrate the database


    if you are using mongodb run the following command
    pnpm generate # use npm or yarn if you prefer

    if you are using postgresql run the following command
    pnpm migrate # use npm or yarn if you prefer
  4. Run the development server

    npm run dev
    
    or
    yarn dev
    
    or
    pnpm dev
  5. Open http://localhost:3000 with your API client testing tool to see the result. Alternatively, you can use the Live Link to test the API.

Usage

Create an acronym

POST: /api/acronym

// Requests
{
	"acronym": "API",
	"definition": "Application Programming Interface"
}

// Response
{
   "id": "652bd508a99c5753e6dd94ec",
   "acronym": "API",
   "definition": "Application Programming Interface",
   "createdAt": "2023-10-15T12:03:20.914Z",
   "updatedAt": "2023-10-15T12:03:20.914Z"
}

Get all acronyms

GET: /api/acronym

[
	{
		"id": "652bd508a99c5753e6dd94ec",
		"acronym": "API",
		"definition": "Application Programming Interface",
		"createdAt": "2023-10-15T12:03:20.914Z",
		"updatedAt": "2023-10-15T12:03:20.914Z"
	},
	{
		"id": "652bd508a99c5753e6dd94ec",
		"acronym": "APIs",
		"definition": "Application Programming Interfaces",
		"createdAt": "2023-10-15T12:03:20.914Z",
		"updatedAt": "2023-10-15T12:03:20.914Z"
	}
]

Get an acronym by id

GET: /api/acronym/:id

// Response
{
	"id": "652bd508a99c5753e6dd94ec",
	"acronym": "API",
	"definition": "Application Programming Interface",
	"createdAt": "2023-10-15T12:03:20.914Z",
	"updatedAt": "2023-10-15T12:03:20.914Z"
}

Update an acronym

PATCH: /api/acronym/:id

// Requests
{
	"acronym": "API - updated",
	"definition": "Application Programming Interface - updated"
}

// Response
{
	"id": "652bd508a99c5753e6dd94ec",
	"acronym": "API",
	"definition": "Application Programming Interface",
	"createdAt": "2023-10-15T12:03:20.914Z",
	"updatedAt": "2023-10-15T12:03:20.914Z"
}

Delete an acronym

DELETE: /api/acronym/:id

// Response
{
	"id": "652bd508a99c5753e6dd94ec",
	"acronym": "API",
	"definition": "Application Programming Interface",
	"createdAt": "2023-10-15T12:03:20.914Z",
	"updatedAt": "2023-10-15T12:03:20.914Z"
}

Pagination

GET: /api/acronym?page=1&limit=10

// Response
{
	"data": [],
	"meta": {
		"totalCoun": 0,
		"totalPages": 0,
		"page": 1,
		"limit": 10,
		"orderBy": "desc"
	}
}

Author