If you have just downloaded this repo, then the first thing you need to do is
'''bash pnpx i #or npm install '''
First, run the development server:
pnpx dev
#or
npm run devOpen http://localhost:3000 with your browser to see the result.
This API allows for managing a list of people, supporting operations to retrieve all people and to add a new person to the list. It is built using Next.js and Prisma.
The Prisma schema for this project defines the structure of the data related to Person. You can find the schema in the prisma/schema.prisma file.
The Person model typically looks like this:
model Person {
id Int @id @default(autoincrement())
firstname String
lastname String
phone String
}Before running the project, you need to set up your .env file in the project's root directory. This file should include the database connection string:
DATABASE_URL="your-database-connection-string"
Replace "your-database-connection-string" with your actual database connection string.
After setting up your .env file, run Prisma migrations to set up your database:
npx prisma migrate devThis command creates the necessary tables in your database according to the Prisma schema.
Returns a list of all people in the database.
No payload is required. Simply send a GET request to /api/people.
[
{
"id": 1,
"firstname": "John",
"lastname": "Doe",
"phone": "123-456-7890"
},
{
"id": 2,
"firstname": "Jane",
"lastname": "Doe",
"phone": "098-765-4321"
}
]Adds a new person to the database.
{
"firstname": "Alice",
"lastname": "Smith",
"phone": "555-1234"
}- Set the method to
POST. - Enter the URL
http://localhost:3000/api/people(adjust the domain/port as necessary for your setup). - In the 'Body' tab, select 'raw' and 'JSON'.
- Paste the sample JSON payload into the body.
- Send the request.
Upon success, you will receive a 202 Accepted status code along with the details of the newly added person.
- If required fields are missing, the API responds with a
400 Bad Request. - For server errors, you will receive a
500 Internal Server Error.