Skip to content

Commit dd32aab

Browse files
committed
updated:readme
1 parent c2a8612 commit dd32aab

File tree

2 files changed

+106
-9
lines changed

2 files changed

+106
-9
lines changed

.env

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
# Environment variables declared in this file are automatically made available to Prisma.
2-
# See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema
31

4-
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
5-
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings
6-
7-
# The following `prisma+postgres` URL is similar to the URL produced by running a local Prisma Postgres
8-
# server with the `prisma dev` CLI command, when not choosing any non-default ports or settings. The API key, unlike the
9-
# one found in a remote Prisma Postgres URL, does not contain any sensitive information.
102

113
DATABASE_URL="postgresql://postgres.uycuryvjjhznvsfumxre:[email protected]:5432/postgres"
124
JWT_SECRET="roshanishacker"

README.md

Lines changed: 106 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,108 @@
11
# Backend-REST-API-JWT-Auth-RoleBased
22

3-
A scalable RESTful backend service implementing JWT authentication, role-based access control, and CRUD operations for managing application data.
3+
A **RESTful API backend** built with **TypeScript**, **Express**, and **Prisma**, featuring **JWT authentication** and **role-based access** for user and blog management. Containerized with **Docker** for easy deployment.
4+
5+
---
6+
7+
## Features
8+
9+
- User registration & login with **JWT** (stored in HTTP-only cookies)
10+
- Role-based access (`USER` and `ADMIN`)
11+
- Blog CRUD: users can manage their posts, admin can manage all posts
12+
- Secure password hashing with **bcrypt**
13+
- Docker-ready
14+
15+
---
16+
17+
## Tech Stack
18+
19+
- Node.js + TypeScript
20+
- Express.js + Prisma (PostgreSQL)
21+
- JWT + bcrypt
22+
- Docker
23+
24+
---
25+
26+
## Environment Variables
27+
28+
Create a `.env` file:
29+
30+
```env
31+
DATABASE_URL="postgresql://username:password@host:port/database"
32+
JWT_SECRET="your-secret-key"
33+
PORT=4000
34+
```
35+
36+
---
37+
38+
## Run Locally
39+
40+
```bash
41+
git clone https://github.com/raone1422g/restapi.git
42+
cd restapi
43+
pnpm install
44+
#make sure you have setup the env variable
45+
npx prisma generate
46+
npx prisma migrate dev --name init
47+
pnpm run dev
48+
```
49+
50+
API runs at: `http://localhost:4000`
51+
52+
---
53+
54+
## Docker
55+
56+
### Pull prebuilt image:
57+
58+
```bash
59+
docker pull raone1422g/restapi:v1.0
60+
```
61+
62+
### Run container:
63+
64+
```bash
65+
docker run -d -p 3000:4000 \
66+
-e DATABASE_URL="your_database_url" \
67+
-e JWT_SECRET="your_jwt_secret" \
68+
raone1422g/restapi:v1.0
69+
```
70+
71+
---
72+
73+
## API Endpoints
74+
75+
### Auth
76+
77+
| Endpoint | Method | Description |
78+
| -------------------- | ------ | --------------------- |
79+
| `/api/auth/register` | POST | Register a user |
80+
| `/api/auth/login` | POST | Login & receive JWT |
81+
| `/api/auth/logout` | POST | Logout (clear cookie) |
82+
| `/api/auth/me` | GET | Get logged-in user |
83+
84+
### Blogs
85+
86+
| Endpoint | Method | Description |
87+
| ---------------------- | ------ | --------------------------- |
88+
| `/api/blog/allBlogs` | GET | Get all posts |
89+
| `/api/blog/getMyBlogs` | GET | Get logged-in user’s posts |
90+
| `/api/blog/create` | POST | Create a post |
91+
| `/api/blog/update/:id` | PUT | Update a post (author only) |
92+
| `/api/blog/delete/:id` | DELETE | Delete a post (author only) |
93+
94+
### Users (Admin Only)
95+
96+
| Endpoint | Method | Description |
97+
| ----------------------- | ------ | ------------------------ |
98+
| `/api/user/getAllUsers` | GET | Get all registered users |
99+
100+
---
101+
102+
## Notes
103+
104+
- All authenticated routes require the JWT cookie.
105+
- Admin-only routes are protected by role-based middleware.
106+
- Passwords are hashed, never stored in plaintext.
107+
108+
---

0 commit comments

Comments
 (0)