(asked ai to check my project and write this readme for me)
REST API for blog management I built with Next.js, Prisma, and TypeScript. It's to Create, read, update, and delete blog posts with a beautiful interface.
- Full CRUD Operations: Create, read, update, and delete blog posts
- Modern Tech Stack: Next.js 14, Prisma ORM, TypeScript, Tailwind CSS
- Database Integration: SQLite database with Prisma for type-safe database operations
- Input Validation: Zod schema validation for all API inputs
- Error Handling: Comprehensive error handling with proper HTTP status codes
- Beautiful UI: Modern, responsive interface with Tailwind CSS
- Real-time Updates: Immediate UI updates after operations
- Type Safety: Full TypeScript coverage throughout the application
- Health Check: API health monitoring endpoint
- Framework: Next.js 14 (App Router)
- Database: SQLite with Prisma ORM
- Language: TypeScript
- Styling: Tailwind CSS
- Validation: Zod
- Development: ESLint, Prettier
- Node.js 18+
- npm or yarn
git clone https://github.com/1cbyc/next-blog-api.git
cd blog-api
npm install
Create a .env.local
file in the root directory:
DATABASE_URL="file:./dev.db"
# Generate Prisma client
npm run db:generate
# Push the schema to the database
npm run db:push
# (Optional) Open Prisma Studio to view/edit data
npm run db:studio
npm run dev
Open https://localhost:3000 to view the application.
Method | Endpoint | Description |
---|---|---|
GET |
/api/posts |
Get all posts |
POST |
/api/posts |
Create a new post |
GET |
/api/posts/[id] |
Get a specific post |
PUT |
/api/posts/[id] |
Update a specific post |
DELETE |
/api/posts/[id] |
Delete a specific post |
Method | Endpoint | Description |
---|---|---|
GET |
/api/health |
Check API health status |
curl -X POST https://localhost:3000/api/posts \
-H "Content-Type: application/json" \
-d '{
"title": "My First Blog Post",
"content": "This is the content of my first blog post.",
"published": true
}'
curl https://localhost:3000/api/posts
curl -X PUT https://localhost:3000/api/posts/[id] \
-H "Content-Type: application/json" \
-d '{
"title": "Updated Title",
"content": "Updated content"
}'
curl -X DELETE https://localhost:3000/api/posts/[id]
npm run dev
- Start development servernpm run build
- Build for productionnpm run start
- Start production servernpm run lint
- Run ESLintnpm run type-check
- Run TypeScript type checkingnpm run db:push
- Push schema to databasenpm run db:studio
- Open Prisma Studionpm run db:generate
- Generate Prisma clientnpm run db:migrate
- Run database migrations
The application uses a simple but effective Post model:
model Post {
id String @id @default(cuid())
title String
content String
published Boolean @default(false)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@map("posts")
}
All API inputs are validated using Zod schemas:
export const createPostSchema = z.object({
title: z.string().min(1, 'Title is required').max(100),
content: z.string().min(1, 'Content is required').max(2000),
published: z.boolean().optional().default(false),
})
Comprehensive error handling with proper HTTP status codes and user-friendly error messages.
- CreatePostForm: Form for creating new posts with validation
- PostCard: Individual post display with edit/delete functionality
- PostsList: List of all posts with real-time updates
- Push your code to GitHub
- Connect your repository to Vercel
- Add environment variables in Vercel dashboard
- Deploy!
The application can be deployed to any platform that supports Next.js:
- Netlify
- Railway
- DigitalOcean App Platform
- AWS Amplify
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License.
- Next.js for the amazing React framework
- Prisma for the type-safe database toolkit
- Tailwind CSS for the utility-first CSS framework
- Zod for runtime type validation
Note: This project is currently under development. The README will be updated as the project evolves.