8000 GitHub - josuemontano/books-api: Example books GraphQL API
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

josuemontano/books-api

Repository files navigation

Books API

This is a FastAPI example app. It features:

screenshot

Quick Start

Install Python 3.9 and Poetry. Then:

# Install dependencies
poetry install

# Spawn a shell within the virtual environment
poetry shell

# Run database migrations
alembic upgrade head

# Start the server
uvicorn api.main:app --reload --host 0.0.0.0

Now you can make requests to the API:

curl --request POST \
  --url http://127.0.0.1:8000/graphql \
  --header 'Content-Type: application/json' \
  --data '{"query":"query { health }"}'

Table of Contents

System requirements

  • Python 3.9+
  • PostgreSQL 12+
  • Redis 5+
  • Node 16+ (only required for the UI)

Make sure the REDIS_URL environment variable is pointing to your Redis server and the DATABASE_URL one is pointing to your PostgreSQL database.

Export the GraphQL schema

You can export the schema of the GraphQL API. It will be described in the GraphQL schema definition language (SDL).

env $(cat .env) strawberry export-schema api.graphql:schema > schema.graphql

Task queue

The task queue is powered by Huey, backed by Redis.

poetry run huey_consumer.py api.queue.huey

There's a periodic task to calculate the value of Pi using the Gregory-Leibniz's series and will publish the result of each iteration to Redis. You can get these values in realtime subscribing to the pi GraphQL subscription of this API.

Client UI

This repo contains a simple UI that you can use to test the API. It is powered by React, Tailwind and Parcel.

# Install dependencies
npm install

# Start the dev server
npm start

Then open http://localhost:1234 in your browser.

0