0% found this document useful (0 votes)
2 views1 page

Flask REST API For Bookstore Management

This document outlines a simple REST API for managing a bookstore using Flask in Python. It includes source code for endpoints to get, add, and delete books. The API is designed to handle basic book management functionalities.

Uploaded by

zacklygammer567
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Flask REST API For Bookstore Management

This document outlines a simple REST API for managing a bookstore using Flask in Python. It includes source code for endpoints to get, add, and delete books. The API is designed to handle basic book management functionalities.

Uploaded by

zacklygammer567
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Flask REST API for Bookstore

Management
Abstract

This project demonstrates a simple REST API for managing a bookstore using Flask in
Python.

Source Code

from flask import Flask, jsonify, request

app = Flask(__name__)
books = [{"id": 1, "title": "1984", "author": "George Orwell"}]

@app.route("/books", methods=["GET"])
def get_books():
return jsonify(books)

@app.route("/books", methods=["POST"])
def add_book():
book = request.get_json()
books.append(book)
return jsonify(book), 201

@app.route("/books/<int:book_id>", methods=["DELETE"])
def delete_book(book_id):
global books
books = [book for book in books if book["id"] != book_id]
return jsonify({"message": "Book deleted"})

if __name__ == "__main__":
app.run(debug=True)

You might also like