diff --git a/api-reference.mdx b/api-reference.mdx new file mode 100644 index 0000000..fcf4765 --- /dev/null +++ b/api-reference.mdx @@ -0,0 +1,93 @@ +```markdown +# API Reference + +## Blog Posts API + +### `GET /api/blog` + +Fetch published blog posts with their authors. + +#### Example Request + +```http +GET /api/blog +``` + +#### Example Response + +```json +[ + { + "id": "clwlskj4a0000bqggs4zpuffq", + "title": "Hello World", + "content": "My first post.", + "published": true, + "authorId": "clwlsj3840000bqggsyj4mfyz", + "createdAt": "2024-06-20T12:00:00.000Z", + "updatedAt": "2024-06-20T12:00:00.000Z", + "author": { + "id": "clwlsj3840000bqggsyj4mfyz", + "name": "Jane Doe", + "email": "jane@example.com" + // ...other user fields + } + } +] +``` + +#### Errors + +If there is an internal error while fetching posts: + +```json +{ + "message": "Error fetching posts" +} +``` + +Status: `500 Internal Server Error` + +--- + +## Database Models + +### `Post` Model + +The `Post` model represents a blog post. + +| Field | Type | Notes | +|------------|-----------|-----------------------------------------------| +| id | String | Primary key, autogenerated | +| title | String | Title of the post | +| content | String? | Post content, optional (`Text` in DB) | +| published | Boolean | `true` if post is published, default: `false` | +| author | User | Relation to the `User` (author) | +| authorId | String | Foreign key to `User` | +| createdAt | DateTime | Defaults to creation time | +| updatedAt | DateTime | Auto-updates on modification | + +#### Prisma Schema Example + +```prisma +model Post { + id String @id @default(cuid()) + title String + content String? @db.Text + published Boolean @default(false) + author User @relation(fields: [authorId], references: [id]) + authorId String + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt +} +``` + +The `User` model now also has + +```prisma +posts Post[] +``` + +to represent the one-to-many relationship between users and posts. + +--- +``` \ No newline at end of file