RESTful Interfaces
Deadline: Monday, April 27, 2026.
Plagiarism is theft and is unacceptable. It undermines creativity, damages intellectual integrity, and destroys the purpose of learning. This also applies to contract cheating (opens in a new tab) and the mindless use of chatbots/agents.1
Requirements
Continuing the flashcards application, use Next.js and Prisma to implement an API based on the class hierarchy and data repositories of 2 Client Rendering.
Models
Create a Next.js application, then install Prisma and initialize it with a SQLite data source provider. Define the following models in prisma/schema.prisma and use cuid(2) to generate the identifiers:
Define a seeding script, prisma/seed.mjs, to create all valid card types. CardType is conceptually an enumeration but is defined as a model instead:
Create the database using a migration, seed it, and verify that it has been created and seeded successfully using Prisma Studio.
Endpoints
Define the following routes and methods to manage the collection of decks, slides, and cards:
| Method | URL | Description |
|---|---|---|
GET | /api | Return all the decks in the collection. |
POST | /api | Create a deck based on the request body and return it. |
DELETE | /api/:deck | Delete the deck having the provided identifier if empty. |
GET | /api/:deck | Return all the slides in a deck. |
POST | /api/:deck | Create a slide based on the request body and return it. |
DELETE | /api/:deck/:slide | Delete the slide having the provided identifier if empty. |
GET | /api/:deck/:slide | Return all the cards in a slide. |
POST | /api/:deck/:slide | Create a card based on the request body and return it. |
DELETE | /api/:deck/:slide/:card | Delete the card having the provided identifier. |
PATCH | /api/:deck/:slide/:card | Update the card having the provided identifier based on the request body. |
Do not access the database directly in the route methods. Instead, use CRUD repositories with corresponding methods for all data operations. Each route method should require only one repository method call.
Respond with the correct status code (opens in a new tab) for successful requests (2xx). For invalid requests, respond with an error status code (4xx, 5xx) and a message. Examples of invalid requests include:
- Accessing a non-existent resource.
- Deleting a non-empty deck or slide.
- Deleting a card from a slide that does not contain it.
You can use the Prisma error code (opens in a new tab) to determine the type of error that occurred in the repository method and respond accordingly. Error details are provided by the repository methods (see Repositories below).
export async function METHOD(request, { params }) {
try {
const { ••• } = await params;
const result = await •••
if ("error" in result) {
return Response.json(•••);
}
return Response.json(•••);
} catch (e) {
return Response.json(•••);
}
}Repositories
Create separate data repository modules under repos for decks, slides, and cards, respectively. These repository modules import Prisma Client and use its CRUD operations (opens in a new tab) to access the underlying database, implementing only the methods needed by the route methods.
Repository methods return the result of their database queries. When a query fails, an exception is thrown by Prisma Client with a corresponding error code (opens in a new tab). Use this code to return an error object, which the route method then uses to respond accordingly.
export async function method(•••) {
try {
const verification = await •••
const result = await •••
return {
data: •••
};
} catch (e) {
return {
error: {
message: •••,
status: •••
}
};
}
}Despite the fact that each deck, slide, and card is uniquely identified by its cuid, every repository method must verify ownership before executing its query:
- Every method in
repos/slides.jsmust verify that the slide belongs to the specified deck. - Every method in
repos/cards.jsmust verify that the card belongs to the specified slide and that the slide belongs to the specified deck.
An error is returned when verification fails. This ensures that each resource is accessed using a single unique URL given our route interface.
Testing
Test all ten route methods using Postman and export the collection to postman.json.
A client application extending 2 Client
Rendering with calls to the
API is provided in the classroom
repository (opens in a new tab)
under public. Copy it to the public directory of your application and use
it to test your implementation.
Guidelines
- Push your solution to your private repository under
assignments/03-restful-interfaces. - Commit often and use meaningful message summaries and descriptions.
- Complete your work before the deadline; no late submissions.
Codebase
The following structure should be used to organize the codebase. There is no need to create additional top-level directories/files, but more directories/files can be created under api and results.
...
dev.db
migration.sql
migration_lock.toml
schema.prismaseed.mjs
cards.jsdecks.jsprisma.jsslides.js
.env.gitignorebiome.jsonjsconfig.jsonnext.config.mjspackage.jsonpostman.jsonprisma.config.mjsreadme.md
Report
Include screenshots of testing with Postman under results and push them
along with the assignment.
Complete the readme.md report and push it along with the assignment.
# Report
Xane Doe [email protected]
## 3 RESTful Interfaces
| Task | Done? | Comments |
| :----------- | :---- | :------------------- |
| Schema | [ ] | |
| Migration | [ ] | |
| Endpoints | [ ] | |
| Validation | [ ] | |
| Repositories | [ ] | |
| Verification | [ ] | |
| Errors | [ ] | |
| Testing | [ ] | |
| Export | [ ] | |
| Screenshots | [ ] | |
| Report | [x] | Markdown is the way. |
| Plagiarism | [ ] | |Rubric
| Task | Points | Details |
|---|---|---|
| Models | +20 | Prisma Schema. Prisma Migrate |
| Endpoints | +30 | Routes/Methods, Requests/Responses, Validation |
| Repositories | +30 | Prisma Client, CRUD subset, Verification, Errors |
| Testing | +20 | Prisma Studio, Postman Collection |
| Screenshots | +5 | |
| Quality | +5 | Clean, structured, well-organized, indented code |
| Report | -20 | Evaluation, Comments |
| Plagiarism | -∞ | |
| Total | 110 |
Footnotes
-
Student Code of Conduct Policy (opens in a new tab) / Article (1) — سياسة النظام الطلابي (opens in a new tab) \ البند (١). ↩