-
Notifications
You must be signed in to change notification settings - Fork 19
Yusup R. #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Yusup R. #15
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| #!/bin/bash | ||
|
|
||
| curl -X DELETE http://localhost:3000/users/11 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| #!/bin/bash | ||
|
|
||
| curl http://localhost:3000/users/11 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| #!/bin/bash | ||
|
|
||
| curl -X PATCH http://localhost:3000/users/11 \ | ||
| -H "Content-Type: application/json" \ | ||
| -d '{ | ||
| "email": "johndoe@example.com" | ||
| }' |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #!/bin/bash | ||
|
|
||
| curl -X POST http://localhost:3000/users \ | ||
| -H "Content-Type: application/json" \ | ||
| -d '{ | ||
| "name": "John Doe", | ||
| "email": "john.doe@example.com", | ||
| "password": "secret123", | ||
| "role": "user", | ||
| "active": true, | ||
| "department": "Engineering" | ||
| }' |
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: I believe the users.json file was supposed to remain in the same state as at the beginning of the project. It's not the focus of the exercise, and it's not an issue either, but it's good to be cautious when committing changes to 'database' files like this one. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,9 @@ import { fetchData } from './fetcher.js'; | |
|
|
||
| const API_BASE_URL = 'https://api.nobelprize.org/2.1'; | ||
|
|
||
| // https://api.nobelprize.org/2.1/nobelPrizes?offset=0&limit=10&sort=desc | ||
| // https://api.nobelprize.org/2.1/nobelPrizes?offset=0&limit=10&sort=desc[&nobelPrizeYear=2020][&nobelPrizeCategory=physics] | ||
|
|
||
| /** | ||
| * Fetch Nobel Prizes with optional filters | ||
| * @param {Object} filters - Filter options | ||
|
|
@@ -15,7 +18,21 @@ const API_BASE_URL = 'https://api.nobelprize.org/2.1'; | |
| * @param {Function} onError - Callback for fetch errors | ||
| */ | ||
| export function fetchNobelPrizes(filters = {}, onSuccess, onError) { | ||
| let url = ''; // TODO Construct the full URL with query parameters; | ||
| let url = `${API_BASE_URL}/nobelPrizes`; | ||
| const params = new URLSearchParams({ | ||
| offset: filters.offset || 0, | ||
| limit: filters.limit || 10, | ||
| sort: 'desc' | ||
| }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good use of the URLSearchParams object constructor for the fixed params 👍 |
||
|
|
||
| // Only add optional filters when not "all" | ||
| if (filters.year !== 'all') { | ||
| params.set('nobelPrizeYear', filters.year); | ||
| } | ||
| if (filters.category !== 'all') { | ||
| params.set('nobelPrizeCategory', filters.category); | ||
| } | ||
|
|
||
| url += `?${params}`; //ADD the query string to the end of url | ||
| fetchData(url, onSuccess, onError); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works because curl uses GET by default. However, I'd consider adding -X GET to make the method explicit and consistent with your other bash scripts.