Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Simple Drink API

A straightforward RESTful API built with Python and Flask that allows users to manage a collection of drinks. This project demonstrates basic CRUD (Create, Read, Update, Delete) operations and serves as a foundational example of building a web API.

Technologies Used

  • Python: The core programming language.
  • Flask: A lightweight web framework for Python.
  • Flask-SQLAlchemy: An extension for Flask that adds support for SQLAlchemy, an Object Relational Mapper (ORM), to simplify database interactions.
  • SQLite: A C-language library that implements a small, fast, self-contained, high-reliability, full-featured, SQL database engine.

Getting Started

To get a local copy up and running, follow these simple steps.

Prerequisites

  • Python 3.x installed on your system.
  • pip for installing Python packages.

Installation

  1. Clone the repository (or download the source code):

    git clone [YOUR_REPOSITORY_URL]
    cd [YOUR_PROJECT_DIRECTORY]
  2. Create and activate a virtual environment:

    • On macOS and Linux:
      python3 -m venv venv
      source venv/bin/activate
    • On Windows:
      python -m venv venv
      .\venv\Scripts\activate
  3. Install the required packages:

    pip install Flask Flask-SQLAlchemy
  4. Initialize the database: From your terminal, start a Python interpreter and run the following commands to create the data.db file and the drink table.

    from application import db
    db.create_all()
    exit()
  5. Run the Flask application:

    flask run

    Your API should now be running at http://127.0.0.1:5000.

API Endpoints

The following are the available endpoints for this API.

Get All Drinks

  • URL: /drinks
  • Method: GET
  • Description: Retrieves a list of all drinks in the database.
  • Success Response:
    • Code: 200 OK
    • Content:
      {
          "drinks": [
              "Water",
              "Coffee"
          ]
      }

Get a Single Drink

  • URL: /drinks/<id>
  • Method: GET
  • Description: Retrieves a specific drink by its ID.
  • Success Response:
    • Code: 200 OK
    • Content:
      {
          "name": "Water",
          "description": "Clear and refreshing"
      }
  • Error Response:
    • Code: 404 Not Found

Add a New Drink

  • URL: /drinks
  • Method: POST
  • Description: Adds a new drink to the database.
  • Request Body:
    {
        "name": "Tea",
        "description": "A warm, comforting beverage"
    }
  • Success Response:
    • Code: 200 OK
    • Content:
      {
          "id": 3
      }

Delete a Drink

  • URL: /drinks/<id>
  • Method: DELETE
  • Description: Deletes a specific drink by its ID.
  • Success Response:
    • Code: 204 No Content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages