Skip to content

Blog Read API Endpoint #4

@Pythonian

Description

@Pythonian

Description

Develop an endpoint to handle requests to fetch and return the details of a specific blog post. This endpoint should be accessible to all users. If the blog post is fetched successfully, it will be returned to the client with a 200 OK status. If an error occurs, an appropriate error status will be returned.

Acceptance Criteria

  • The endpoint allows users to fetch the details of a specific blog post by its ID.
  • The endpoint is accessible to all users.
  • The endpoint validates the blog post ID and returns appropriate error messages for invalid IDs.
  • Returns a 200 OK status code and the blog post details when the blog post is fetched successfully.

Requirements

  • Implement API endpoint for fetching the details of a specific blog post.
  • Validate the blog post ID and return appropriate error messages for invalid IDs.
  • Handle unexpected errors and return the appropriate status code.
  • Ensure soft-deleted blog posts are not returned.

Expected Outcome

  • Users should be able to send a request to fetch the details of a specific blog post.
  • Users should receive appropriate status codes and responses based on the outcome of the request.

Endpoints

[GET] /api/v1/blogs/:id

  • Description: Fetches the details of a specific blog post.

  • Path Parameters:

    • id: The ID of the blog post to fetch.
  • Success Response:

    • Status: 200 OK

    • Body:

      {
        "id": "id",
        "title": "Blog Post Title",
        "excerpt": "Blog post excerpt here.",
        "content": "Content of the blog post...",
        "image_url": "image-url-link",
        "created_at": "2024-07-18T00:00:00Z",
        "updated_at": "2024-07-18T00:00:00Z",
      }
  • Error Response:

    • Status: 500 Internal Server Error

    • Body:

      {
          "error": "Internal server error."
      }
  • Not Found Response:

    • Status: 404 Not Found

    • Body:

      {
          "error": "Blog post not found."
      }
  • Bad Request Response:

    • Status: 400 Bad Request

    • Body:

      {
          "error": "Invalid blog post ID."
      }

Testing

Test Scenarios

  1. Successful Retrieval of Blog Post

    • Ensure that the endpoint successfully retrieves the details of an existing blog post.
    • Verify that the response includes the blog post details and a 200 OK status code.
  2. Blog Post Not Found

    • Simulate a request to fetch a blog post that does not exist.
    • Confirm that the endpoint returns a 404 Not Found status code and an appropriate error message.
  3. Internal Server Error

    • Simulate an internal server error to raise an exception.
    • Verify that the endpoint returns a 500 Internal Server Error status code and an appropriate error message.
  4. Invalid Blog Post ID

    • Send requests with invalid blog post IDs (e.g., non-integer values).
    • Verify that the endpoint returns a 400 Bad Request status code and an appropriate error message.
  5. Soft-Deleted Blog Post Access Control

    • Ensure that soft-deleted blog posts are not returned in regular queries.
    • Confirm that the endpoint returns a 404 Not Found status code and an appropriate error message.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions