A simple TypeScript database service for your RequestBin clone using PostgreSQL + MongoDB.
cdinto backend directory.
cd backend- Install dependencies:
npm install- Set up environment variables (copy
.env.exampleto.envand fill in your values):
cp .env.example .env- Make sure PostgreSQL and MongoDB are running.
4.1. Create the PostgreSQL database (MongoDB creates its database automatically):
createdb requestbin
# If you get a permission error, try: createdb -U <your_username> requestbinNote: If your PostgreSQL user isn't postgres, update PG_USER in your .env file. On macOS with Homebrew, it's usually your system username.
- Run the test script to verify everything works:
npm run dbtest- Start the backend dev server
npm run dev- Create bin
Request body
{
"bin_route": "abc123",
}Response: 201
{
"bin_route": "abc123",
"token": "sk_92fj3k1"
}Note
- The token is generated by the server and returned in the response.
- Save both
bin_routeandtokenas they are needed to view the bin.
Unsuccessful responses
- 400
{"error":"Invalid JSON: "bin_route" is required."} - 400
{"error":"Invalid JSON: "bin_route" must be a string."} - 409
{"error":"Bin with route <binRoute> already exists."}
- Collect webhook request in bin (accepts any method).
- Replace
:binRoutewithbin_routereturned fromPOST /bins.
- Replace
Response: 204
- No content
Unsuccessful responses
- 404
{"error":"Bin with route <binRoute> not found."}
- Retrieve list of requests in bin
- Requires header:
Authorization: Bearer <token>
- Requires header:
Response: 200
{
"bin_route": "abc123",
"requests": [
{
"method": "POST",
"created_at": "2026-03-07 19:12:45",
"path": "/in/abc123",
"headers": { "content-type": "application/json" },
"params": { "category": "webhooks" },
"body": { "example": true }
}
]
}Note
- If a request's body cannot be returned as JSON, it will be returned as a string instead.
Unsuccessful responses
- 401
{"error":"Unauthorized: No token provided"} - 401
{"error":"Unauthorized: Token invalid"} - 404
{"error":"Bin with route <binRoute> not found."}
- Delete a bin and all requests
- Requires header:
Authorization: Bearer <token>
- Requires header:
Response: 204
- No content
Unsuccessful responses
- 401
{"error":"Unauthorized: No token provided"} - 401
{"error":"Unauthorized: Token invalid"} - 404
{"error":"Bin with route <binRoute> not found."}