Coder Social home page Coder Social logo

classical-piano-api's Introduction

Classical Piano API

A small FastAPI app that manages composers and pieces.

Endpoints

GET /composers

Returns a list of composers

Example:

[
  {
    "name": "Sergei Rachmaninoff",
    "composer_id": 1,
    "home_country": "Russia"
  },
  {
    "name": "Franz Liszt",
    "composer_id": 2,
    "home_country": "Hungary"
  }
]

GET /pieces

Returns a list of pieces

  • Query Parameters:
    • composer_id (int) - An optional ID of the composer to filter on

Example:

[
  {
    "name": "Etude Tableaux Op. 39 No. 6",
    "alt_name": "Little Red Riding Hood",
    "difficulty": 9,
    "composer_id": 1
  },
  {
    "name": "Waltz Op. 18 No. 1 in E-Flat Major",
    "alt_name": "Grande valse brillante",
    "difficulty": 4,
    "composer_id": 4
  }
]

POST /composers

Creates a new composer

  • Body:

    • name (string) - Name of the composer
    • composer_id (int) - ID of the composer (consider making this auto incrementing so the user doesn't have to pass it in). Raise an HTTP 400 if a duplicate ID is passed in.
    • home_country (string) - Country the composer was born in

    Example body:

{
  "name": "Sergei Rachmaninoff",
  "composer_id": 1,
  "home_country": "Russia"
}

POST /pieces

Creates a new piece

  • Body:
    • name (string) - Name of the piece
    • alt_name (string) - Optional alternate name of the piece
    • difficulty (int) - Difficulty rating of the piece (1-10) (consider restricting the difficulty input to only accept 1-10)
    • composer_id (int) - ID of the composer. Raise HTTP 400 exception if the composer ID doesn't exist.

Example body:

{
  "name": "Etude Tableaux Op. 39 No. 6",
  "alt_name": "Little Red Riding Hood",
  "difficulty": 9,
  "composer_id": 1
}

PUT /composers/{composer_id}

Updates a composer if they exist, otherwise they are created

  • Query parameters:

    • composer_id (int) - ID of the composer
  • Body:

    • name (string) - Name of the composer
    • composer_id (int) - ID of the composer (consider making this auto incrementing so the user doesn't have to pass it in). Raise an HTTP 400 if a duplicate ID is passed in.
    • home_country (string) - Country the composer was born in

    Example body:

{
  "name": "Sergei Rachmaninoff",
  "composer_id": 1,
  "home_country": "Russia"
}

PUT /pieces/{piece_name}

Updates a piece if it exists, otherwise it is created

  • Query parameters:

    • piece_name (string) - Name of the piece
  • Body:

    • name (string) - Name of the piece
    • alt_name (string) - Optional alternate name of the piece
    • difficulty (int) - Difficulty rating of the piece (1-10) (consider restricting the difficulty input to only accept 1-10)
    • composer_id (int) - ID of the composer. Raise HTTP 400 exception if the composer ID doesn't exist.

Example body:

{
  "name": "Etude Tableaux Op. 39 No. 6",
  "alt_name": "Little Red Riding Hood",
  "difficulty": 9,
  "composer_id": 1
}

DELETE /composers/{composer_id}

Deletes a composer

  • Query parameters:
    • composer_id (int) - ID of the composer

DELETE /pieces/{piece_name}

Deletes a piece

  • Query parameters:
    • piece_name (string) - Name of the piece

Installation/Running instructions

Run db.py to build database and inject existing json data into table.

Run uvicorn main:app --reload to run uvicorn back end server

classical-piano-api's People

Contributors

mike-jacks avatar greganderson 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.