This is a simple API that allows you to create, read, update and delete acronyms.
-
Install the dependencies
npm install or yarn or pnpm install
-
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
-
Run the Prisma commands to generate the Prisma client and migrate the database
if you are using mongodb run the following commandpnpm generate # use npm or yarn if you prefer
if you are using postgresql run the following commandpnpm migrate # use npm or yarn if you prefer
-
Run the development server
npm run dev or yarn dev or pnpm dev
-
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.
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: /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: /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"
}
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: /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"
}
GET: /api/acronym?page=1&limit=10
// Response
{
"data": [],
"meta": {
"totalCoun": 0,
"totalPages": 0,
"page": 1,
"limit": 10,
"orderBy": "desc"
}
}