Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .postman/resources.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Use this workspace to collaborate
workspace:
id: 9228adbf-de74-4b01-afc0-3a536f8c5d91

# All resources in the `postman/` folder are automatically registered in Local View.
# Point to additional files outside the `postman/` folder to register them individually. Example:
#localResources:
# collections:
# - ../tests/E2E Test Collection/
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ curl -X PUT http://localhost:3000/api/v1/books/1 \
-d '{"title":"Dune","author":"Frank Herbert","year":1965}'
```

**Delete book**
**Delete a book**
```bash
curl -X DELETE http://localhost:3000/api/v1/books/1
```
Expand Down
8 changes: 8 additions & 0 deletions postman/collections/Book-API/.resources/definition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$kind: collection
name: Book API
description: A REST API for managing books. This collection provides endpoints
for creating, reading, updating, and deleting books, as well as health check
and API info endpoints.
variables:
baseUrl: http://localhost:3000
bookId: ""
4 changes: 4 additions & 0 deletions postman/collections/Book-API/Books/.resources/definition.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
$kind: collection
name: Books
description: CRUD operations for managing books
order: 2000
42 changes: 42 additions & 0 deletions postman/collections/Book-API/Books/Create Book.request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
$kind: http-request
name: Create Book
method: POST
url: '{{baseUrl}}/api/v1/books'
order: 3000
headers:
- key: Content-Type
value: application/json
body:
type: json
content: |-
{
"title": "The Great Gatsby",
"author": "F. Scott Fitzgerald",
"year": 1925,
"publisher": "Charles Scribner's Sons"
}
scripts:
- type: afterResponse
language: text/javascript
code: |-
pm.test("Status code is 201", function () {
pm.response.to.have.status(201);
});

pm.test("Response has 'book' with 'id'", function () {
const jsonData = pm.response.json();
pm.expect(jsonData).to.have.property("book");
pm.expect(jsonData.book).to.have.property("id");
});

pm.test("Book title matches request", function () {
const jsonData = pm.response.json();
pm.expect(jsonData.book.title).to.eql("The Great Gatsby");
});

pm.test("Store bookId in collection variables", function () {
const jsonData = pm.response.json();
if (jsonData.book && jsonData.book.id) {
pm.collectionVariables.set("bookId", jsonData.book.id);
}
});
26 changes: 26 additions & 0 deletions postman/collections/Book-API/Books/Delete Book.request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
$kind: http-request
name: Delete Book
method: DELETE
url: '{{baseUrl}}/api/v1/books/:id'
order: 5000
pathVariables:
- key: id
value: '1'
description: The unique identifier of the book to delete
scripts:
- type: afterResponse
language: text/javascript
code: |-
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});

pm.test("Response has 'message' equal to 'Book deleted'", function () {
const jsonData = pm.response.json();
pm.expect(jsonData.message).to.eql("Book deleted");
});

pm.test("Response has 'id' property", function () {
const jsonData = pm.response.json();
pm.expect(jsonData).to.have.property("id");
});
29 changes: 29 additions & 0 deletions postman/collections/Book-API/Books/Get Book.request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
$kind: http-request
name: Get Book
method: GET
url: '{{baseUrl}}/api/v1/books/:id'
order: 2000
pathVariables:
- key: id
value: '1'
description: The unique identifier of the book
scripts:
- type: afterResponse
language: text/javascript
code: |-
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});

pm.test("Response has 'book' object", function () {
const jsonData = pm.response.json();
pm.expect(jsonData).to.have.property("book");
pm.expect(jsonData.book).to.be.an("object");
});

pm.test("Book has id, title, author fields", function () {
const jsonData = pm.response.json();
pm.expect(jsonData.book).to.have.property("id");
pm.expect(jsonData.book).to.have.property("title");
pm.expect(jsonData.book).to.have.property("author");
});
22 changes: 22 additions & 0 deletions postman/collections/Book-API/Books/List Books.request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
$kind: http-request
name: List Books
method: GET
url: '{{baseUrl}}/api/v1/books'
order: 1000
scripts:
- type: afterResponse
language: text/javascript
code: |-
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});

pm.test("Response has 'books' array", function () {
const jsonData = pm.response.json();
pm.expect(jsonData).to.have.property("books");
pm.expect(jsonData.books).to.be.an("array");
});

pm.test("Response time under 500ms", function () {
pm.expect(pm.response.responseTime).to.be.below(500);
});
43 changes: 43 additions & 0 deletions postman/collections/Book-API/Books/Update Book.request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
$kind: http-request
name: Update Book
method: PUT
url: '{{baseUrl}}/api/v1/books/:id'
order: 4000
headers:
- key: Content-Type
value: application/json
pathVariables:
- key: id
value: '1'
description: The unique identifier of the book to update
body:
type: json
content: |-
{
"title": "Updated Title",
"author": "Updated Author",
"year": 2024,
"publisher": "Updated Publisher"
}
scripts:
- type: afterResponse
language: text/javascript
code: |-
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});

pm.test("Response has 'book' object", function () {
const jsonData = pm.response.json();
pm.expect(jsonData).to.have.property("book");
pm.expect(jsonData.book).to.be.an("object");
});

pm.test("Book has all required fields", function () {
const jsonData = pm.response.json();
pm.expect(jsonData.book).to.have.property("id");
pm.expect(jsonData.book).to.have.property("title");
pm.expect(jsonData.book).to.have.property("author");
pm.expect(jsonData.book).to.have.property("year");
pm.expect(jsonData.book).to.have.property("publisher");
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
$kind: collection
name: Health & Info
description: Health check and API information endpoints
order: 1000
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
$kind: http-request
name: Health Check
method: GET
url: '{{baseUrl}}/health'
order: 2000
scripts:
- type: afterResponse
language: text/javascript
code: |-
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});

pm.test("Status is 'ok'", function () {
const jsonData = pm.response.json();
pm.expect(jsonData.status).to.eql("ok");
});

pm.test("Response has valid timestamp", function () {
const jsonData = pm.response.json();
pm.expect(jsonData).to.have.property("timestamp");
pm.expect(new Date(jsonData.timestamp).getTime()).to.be.a("number");
});
22 changes: 22 additions & 0 deletions postman/collections/Book-API/Health & Info/Root.request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
$kind: http-request
name: Root
method: GET
url: '{{baseUrl}}/'
order: 1000
scripts:
- type: afterResponse
language: text/javascript
code: |-
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});

pm.test("Response has 'message' equal to 'Book API'", function () {
const jsonData = pm.response.json();
pm.expect(jsonData.message).to.eql("Book API");
});

pm.test("Response has 'docs' property", function () {
const jsonData = pm.response.json();
pm.expect(jsonData).to.have.property("docs");
});
2 changes: 2 additions & 0 deletions postman/globals/workspace.globals.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
name: Globals
values: []