This is a backend API for a Medium.com clone, built with Node.js, Express, and Prisma. It adheres to the RealWorld API specification.
- Node.js: A JavaScript runtime built on Chrome's V8 JavaScript engine.
- Express: A fast, unopinionated, minimalist web framework for Node.js.
- Prisma: A next-generation ORM for Node.js and TypeScript.
- JSON Web Tokens (JWT): Used for authentication.
- Zod: A TypeScript-first schema declaration and validation library.
The API exposes the following endpoints:
- Authentication:
POST /api/users/login
: Login a user.POST /api/users
: Register a new user.
- User:
GET /api/user
: Get the current user.PUT /api/user
: Update the current user.
- Profiles:
GET /api/profiles/:username
: Get a user's profile.POST /api/profiles/:username/follow
: Follow a user.DELETE /api/profiles/:username/follow
: Unfollow a user.
- Articles:
GET /api/articles
: Get recent articles globally.GET /api/articles/feed
: Get recent articles from followed users.GET /api/articles/:slug
: Get a single article.POST /api/articles
: Create a new article.PUT /api/articles/:slug
: Update an article.DELETE /api/articles/:slug
: Delete an article.POST /api/articles/:slug/comments
: Add a comment to an article.GET /api/articles/:slug/comments
: Get comments for an article.DELETE /api/articles/:slug/comments/:id
: Delete a comment.POST /api/articles/:slug/favorite
: Favorite an article.DELETE /api/articles/:slug/favorite
: Unfavorite an article.
- Clone the repository:
git clone https://github.com/your-username/realworld-api.git
- Install dependencies:
npm install
- Set up your environment variables in a
.env
file. You'll need aJWT_SECRET
and aDATABASE_URL
. - Run the database migrations:
npx prisma migrate dev
- Start the server:
npm run dev
The server will be running on http://localhost:3000
.
This API is built to conform to the RealWorld backend API specification.