Skip to content
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

🔹 Issue 5: Fetch and Return Data from an External API #2

Open
krishnaagarwal781 opened this issue Jan 31, 2025 · 0 comments
Open

Comments

@krishnaagarwal781
Copy link
Owner

krishnaagarwal781 commented Jan 31, 2025

GitHub Issue: Fetch Placeholder Data from External API
Task
Create an endpoint /fetch-post/{post_id} that fetches a post from the JSONPlaceholder API and returns the data.

Requirements
Use httpx to fetch data from JSONPlaceholder.
Accept a post_id parameter in the request URL.
Extract and return the following fields:
Title
Body
Handle errors if the post ID is invalid.
Acceptance Criteria
✅ Fetch data successfully and return:

json
Copy
Edit
{
"title": "Sample Post Title",
"body": "This is the content of the post."
}
✅ Handle invalid post IDs by returning a 404 Not Found error.

API Endpoint to Use
arduino
Copy
Edit
https://jsonplaceholder.typicode.com/posts/{post_id}
Additional Notes
Ensure proper exception handling in case of API failures.
Use FastAPI’s HTTPException for error responses.
Would you like the solution code as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant