Git Product home page Git Product logo

movies-api's Introduction

Simple API using Python and Strawberry

Implemented a simple API that fetches movie data using the OMDB API.

Environment Variables

To run this project, you will need to add a .env file to the root of this project and the following environment variables to your .env file:

  • API_KEY

  • PORT

Run Locally

Create and activate a virtual environment

python -m venv venv
source venv/bin/activate

To deploy this project run

  docker-compose up

The app will be running at http://localhost:8000 (or whatever port you used in the PORT variable).

Usage/Examples

Query

query getMovies {
  getMovie(title: "Harry Potter", first: 2) {
    edges {
      node {
        id
        imdbID
        Title
        Type
        Poster
      }
    }
    pageInfo {
      hasNextPage
    }
  }
}

Expected Result

{
  "data": {
    "getMovie": {
      "edges": [
        {
          "node": {
            "id": 1,
            "imdbID": "tt1201607",
            "Title": "Harry Potter and the Deathly Hallows: Part 2",
            "Type": "movie",
            "Poster": "https://m.media-amazon.com/images/M/MV5BMGVmMWNiMDktYjQ0Mi00MWIxLTk0N2UtN2ZlYTdkN2IzNDNlXkEyXkFqcGdeQXVyODE5NzE3OTE@._V1_SX300.jpg"
          }
        },
        {
          "node": {
            "id": 2,
            "imdbID": "tt0241527",
            "Title": "Harry Potter and the Sorcerer's Stone",
            "Type": "movie",
            "Poster": "https://m.media-amazon.com/images/M/MV5BNmQ0ODBhMjUtNDRhOC00MGQzLTk5MTAtZDliODg5NmU5MjZhXkEyXkFqcGdeQXVyNDUyOTg3Njg@._V1_SX300.jpg"
          }
        }
      ],
      "pageInfo": {
        "hasNextPage": true
      }
    }
  }
}

Lessons Learned

I decided to use Strawberry instead of Graphene since it is the recommended library as per FastAPI documentation.

While working on this project, one of the steps was applying Pagination to the query. I quickly realized that Strawberry's documentation had many errors and their tutorial did not work. I spent some time on this issue and was able to fix.

I ended up opening a PR request w/ Strawberry to fix their documentation.

The moral of the story is that with one simple project I ended up contributing to an open-source project (albeit a very small contribution) and perhaps helping someone use this library.

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.