Skip to content

Commit c3a7f63

Browse files
authored
Merge pull request #1 from Postman-Devrel/feat/setup-postman
chore: updated GitHub Action file
2 parents 3f65e24 + f1df1c2 commit c3a7f63

32 files changed

Lines changed: 386 additions & 2443 deletions

.github/workflows/postman.yaml

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,44 @@ jobs:
1313
steps:
1414
- uses: actions/checkout@v4
1515

16-
- uses: actions/setup-node@v4
16+
- run: curl -o- "https://dl-cli.pstmn.io/install/unix.sh" | sh
17+
18+
- name: Set up Node.js
19+
uses: actions/setup-node@v4
1720
with:
18-
node-version: "20"
19-
cache: "yarn"
21+
node-version: 20
22+
cache: "npm"
2023

21-
- run: curl -o- "https://dl-cli.pstmn.io/install/unix.sh" | sh
24+
- name: Install dependencies
25+
run: npm install
2226

23-
- name: Validate and sync
27+
- name: Start server in background
28+
run: |
29+
npm run dev &
30+
echo $! > pidfile
31+
# Wait for server to be ready (port 3000)
32+
for i in {1..20}; do
33+
if nc -z localhost 3000; then
34+
echo "Server is up!"
35+
break
36+
fi
37+
echo "Waiting for server..."
38+
sleep 2
39+
done
40+
41+
- name: Validate Collection and Push to Cloud
2442
env:
2543
POSTMAN_API_KEY: ${{ secrets.POSTMAN_API_KEY }}
2644
run: |
2745
postman login --with-api-key "$POSTMAN_API_KEY"
28-
yarn install --frozen-lockfile
29-
yarn start &
30-
sleep 3
31-
yarn test:api
46+
postman collection run ./postman/collections/Book-API
47+
postman workspace prepare
3248
postman workspace push -y
49+
50+
- name: Stop server
51+
if: always()
52+
run: |
53+
if [ -f pidfile ]; then
54+
kill $(cat pidfile) || true
55+
rm pidfile
56+
fi

.postman/resources.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Use this workspace to collaborate
2+
workspace:
3+
id: 6c050d74-b1e6-4dfb-943e-2f7a2565e4e5
4+
5+
# All resources in the `postman/` folder are automatically registered in Local View.
6+
# Point to additional files outside the `postman/` folder to register them individually. Example:
7+
#localResources:
8+
# collections:
9+
# - ../tests/E2E Test Collection/

README.md

Lines changed: 51 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,106 +1,82 @@
1-
# 🌌 Intergalactic Bank API
1+
# Book API
22

3-
REST API for bank accounts and transactions with multi-currency support (COSMIC_COINS, GALAXY_GOLD, MOON_BUCKS).
3+
Simple REST API for books – CRUD only, no auth. Good for demos and learning.
44

5-
## Quick Start
5+
## Quick start
66

77
```bash
88
npm install && npm run dev
9-
curl http://localhost:3000/health
109
```
1110

12-
Default: **http://localhost:3000**. Generate API key: `GET /api/v1/auth`. Default admin key: `1234`.
11+
Base URL: **http://localhost:3000**
1312

1413
## Endpoints
1514

16-
| Endpoint | Method | Auth | Description |
17-
|----------|--------|------|-------------|
18-
| `/health` | GET | No | Health check |
19-
| `/api/v1/auth` | GET | No | Generate API key |
20-
| `/api/v1/accounts` | GET, POST | Yes | List / create accounts |
21-
| `/api/v1/accounts/:id` | GET, PUT, DELETE | Yes | Get / update / delete (soft) |
22-
| `/api/v1/transactions` | GET, POST | Yes | List / transfer or deposit |
23-
| `/api/v1/transactions/:id` | GET | Yes | Get transaction |
15+
| Method | Endpoint | Description |
16+
|--------|----------|-------------|
17+
| GET | `/health` | Health check |
18+
| GET | `/api/v1/books` | List all books |
19+
| GET | `/api/v1/books/:id` | Get one book |
20+
| POST | `/api/v1/books` | Create a book |
21+
| PUT | `/api/v1/books/:id` | Update a book |
22+
| DELETE | `/api/v1/books/:id` | Delete a book |
2423

25-
**Auth:** send `x-api-key: your-key` on all protected routes. **Rate limit:** 300 req/min per key.
24+
No authentication required.
2625

27-
## Postman
26+
## Examples
2827

29-
1. Import `OpenAPI/Bank API Reference Documentation.postman_collection.json`
30-
2. Set `baseUrl``http://localhost:3000`, `apiKey``1234`
31-
32-
## Commands
33-
34-
| Command | Description |
35-
|---------|-------------|
36-
| `npm run dev` | Dev server (auto-reload) |
37-
| `npm start` | Production |
38-
| `npm test` | Run tests |
39-
| `npm test -- --coverage` | Tests + coverage |
40-
| `npm run lint` | Lint |
41-
42-
## Config (optional `.env`)
43-
44-
```
45-
PORT=3000
46-
ADMIN_API_KEY=1234
47-
RATE_LIMIT_REQUESTS=300
48-
RATE_LIMIT_WINDOW_MS=60000
49-
```
50-
51-
## Project Layout
52-
53-
```
54-
src/
55-
├── server.js # Entry
56-
├── database/db.js # In-memory store
57-
├── models/ # Account, Transaction
58-
├── routes/ # admin, accounts, transactions
59-
└── middleware/ # auth, errorHandler, rateLimit
28+
**List books**
29+
```bash
30+
curl http://localhost:3000/api/v1/books
6031
```
6132

62-
## Important Behavior
63-
64-
- **Ownership** – Accounts are scoped to the API key that created them.
65-
- **Soft delete** – Deleted accounts are flagged; history kept.
66-
- **Editable** – Only `owner` and `accountType`; balance/currency change via transactions only.
67-
68-
## Example Requests
69-
70-
**Create account** `POST /api/v1/accounts`:
71-
```json
72-
{ "owner": "John Doe", "currency": "COSMIC_COINS", "balance": 1000, "accountType": "STANDARD" }
33+
**Create book**
34+
```bash
35+
curl -X POST http://localhost:3000/api/v1/books \
36+
-H "Content-Type: application/json" \
37+
-d '{"title":"Dune","author":"Frank Herbert","year":1965}'
7338
```
7439

75-
**Transfer** `POST /api/v1/transactions`:
76-
```json
77-
{ "fromAccountId": "123", "toAccountId": "456", "amount": 500, "currency": "COSMIC_COINS" }
40+
**Update book** (PUT with full or partial fields)
41+
```bash
42+
curl -X PUT http://localhost:3000/api/v1/books/1 \
43+
-H "Content-Type: application/json" \
44+
-d '{"title":"Dune","author":"Frank Herbert","year":1965}'
7845
```
7946

80-
**Deposit** – Use `"fromAccountId": "0"`.
81-
82-
## Error Format
83-
84-
```json
85-
{ "error": { "name": "errorType", "message": "Description" } }
47+
**Delete book**
48+
```bash
49+
curl -X DELETE http://localhost:3000/api/v1/books/1
8650
```
8751

88-
Common codes: **400** validation, **401** auth, **403** forbidden, **404** not found, **429** rate limit, **500** server error.
52+
## Book shape
8953

90-
## Sample Data (on startup)
54+
- **title** (string, required)
55+
- **author** (string, required)
56+
- **year** (number, optional)
9157

92-
- Nova Newman (10k COSMIC_COINS), Gary Galaxy (237 COSMIC_COINS), Luna Starlight (5k GALAXY_GOLD) – all under admin key `1234`.
58+
Responses use `{ book: {...} }` or `{ books: [...] }`. Errors use `{ error: { name, message } }`.
9359

94-
## Account Types & Currencies
60+
## Commands
9561

96-
**Types:** STANDARD, PREMIUM, BUSINESS. **Currencies:** COSMIC_COINS, GALAXY_GOLD, MOON_BUCKS.
62+
- `npm run dev` – dev server with reload
63+
- `npm start` – production
64+
- `npm test` – run tests
65+
- `npm run lint` – lint
9766

98-
## Replacing Storage
67+
## Project layout
9968

100-
Swap in a real DB by updating `src/database/db.js` with your driver and CRUD; the rest of the app stays the same.
69+
```
70+
src/
71+
├── server.js
72+
├── database/db.js # In-memory store
73+
├── models/Book.js
74+
├── routes/books.js
75+
└── middleware/errorHandler.js
76+
```
10177

102-
---
78+
## Config
10379

104-
**More detail**`CLAUDE.md` · **Tests**`npm test`
80+
Optional `.env`: `PORT=3000`
10581

10682
License: ISC
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
$kind: collection
2+
name: Book API
3+
variables:
4+
- key: baseUrl
5+
value: 'http://localhost:3000'
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
$kind: http-request
2+
name: Create Book
3+
method: POST
4+
url: '{{baseUrl}}/api/v1/books'
5+
order: 3000
6+
headers:
7+
- key: Content-Type
8+
value: application/json
9+
body:
10+
type: json
11+
content: |-
12+
{
13+
"title": "The Great Gatsby",
14+
"author": "F. Scott Fitzgerald",
15+
"year": 1925
16+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
$kind: http-request
2+
name: Delete Book
3+
method: DELETE
4+
url: '{{baseUrl}}/api/v1/books/:id'
5+
order: 5000
6+
pathVariables:
7+
- key: id
8+
value: '1'
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
$kind: http-request
2+
name: 'Get Book by ID'
3+
method: GET
4+
url: '{{baseUrl}}/api/v1/books/:id'
5+
order: 2000
6+
pathVariables:
7+
- key: id
8+
value: '1'
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
$kind: http-request
2+
name: List All Books
3+
method: GET
4+
url: '{{baseUrl}}/api/v1/books'
5+
order: 1000
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
$kind: http-request
2+
name: Update Book
3+
method: PUT
4+
url: '{{baseUrl}}/api/v1/books/:id'
5+
order: 4000
6+
pathVariables:
7+
- key: id
8+
value: '1'
9+
headers:
10+
- key: Content-Type
11+
value: application/json
12+
body:
13+
type: json
14+
content: |-
15+
{
16+
"title": "The Great Gatsby (Updated)",
17+
"author": "F. Scott Fitzgerald",
18+
"year": 1925
19+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
$kind: http-request
2+
name: Health Check
3+
method: GET
4+
url: '{{baseUrl}}/health'
5+
order: 2000

0 commit comments

Comments
 (0)