Giter Club home page Giter Club logo

blog-api's Introduction

Blog Platform API

This is a simple RESTful API for a blogging platform built using FastAPI and MongoDB.

Installation

  1. Clone the repository.
  2. Install dependencies using pip install -r requirements.txt.
  3. Start the server with uvicorn main:app --reload.
  4. Ensure that you have MongoDB installed locally, documentation is at MongoDB Documentation.

Usage

  • Visit /docs endpoint to view API documentation.
  • Create, read, update, and delete blog posts.
  • Comment on posts.
  • Like/dislike posts.

Authentication

Authentication is not required to access the API. All endpoints are publicly accessible.

Error Handling

The API returns appropriate HTTP status codes along with descriptive error messages in case of errors. Common error codes include:

  • 404 Not Found: Resource not found.
  • 400 Bad Request: Invalid request data or parameters.
  • 500 Internal Server Error: Unexpected server error.

Endpoints

Postman was used to test these endpoints:

Creating a New Post

  • Method: POST
  • Request Body: JSON object representing the post.
  • Response: JSON object with a message indicating the success or failure of the operation along with the ID of the newly created post. curl -X POST "http://localhost:8000/posts/" -H "Content-Type: application/json" -d '{"title": "Test Post", "content": "This is a test post content", "author": "Test User"}' image

Getting All Posts

Getting a Post by ID

Updating a Post

  • Method: PUT
  • Request Body: JSON object representing the updated post.
  • Response: JSON object with a message indicating the success or failure of the operation. curl -X PUT "http://localhost:8000/posts/{post_id}" -H image

Deleting a Post

Creating a New Comment on a Post

  • Method: POST
  • Request Body: JSON object representing the comment.
  • Response: JSON object with a message indicating the success or failure of the operation. curl -X POST "http://localhost:8000/posts/{post_id}/comments/" -H "Content-Type: application/json" -d '{"content": "This is a test comment", "author": "Test Commenter"}' image

Liking Post

Disliking Post

Additional Notes

  • The API does not support user authentication or authorization. All actions are performed anonymously.
  • Posts and comments are stored in a MongoDB database. Ensure that the database connection is configured correctly before using the API.
  • When updating a post, both the timestamp and last_updated fields are automatically updated to the current date and time.
  • The API follows RESTful principles for URL structure and HTTP methods.
  • Use appropriate HTTP status codes and error messages to handle client requests effectively.

Contributing

Feel free to contribute by opening issues or submitting pull requests.

License

This project is licensed under the MIT License - see the LICENSE file for details.

blog-api's People

Contributors

lixelamos avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.