GithubHelp home page GithubHelp logo

kdcokenny / fastapi-router Goto Github PK

View Code? Open in Web Editor NEW

This project forked from albakore/fastapi-router

0.0 0.0 0.0 133 KB

a plugin for applications built with FastAPI that enables the development of backend applications with a workflow similar to Next.js.✨

Python 100.00%

fastapi-router's Introduction

FastAPI-Router

Efficient Backend, Agile Development.

installation from PyPI

pip install fastapi-router

installation from Test PyPI

pip install -i https://test.pypi.org/simple/ --extra-index-url https://pypi.python.org/simple/ fastapi-router

FastAPI-Router is a plugin for applications built with FastAPI that enables the development of backend applications with a workflow similar to Next.js. This means you can create efficient and modern backend applications with FastAPI-Router, taking advantage of its capabilities in a manner akin to the workflow in Next.js.

Example:

from fastapi import FastAPI
from fastapi_router import init_main_route

# Init FastAPI application
app = FastAPI()

# Init fastapi-route
init_main_route(app)

API Folder organization

In the FastAPI-Router library, the organization of files within the directory mirrors the route structure, akin to the approach in Next.js.

Each nested folder signifies a route segment, aligning with a corresponding segment in the URL path.

However, the definition of a route doesn't become publicly accessible until a route.py file is added to the respective route segment. This file, acting as the handler, determines the behavior and functionality associated with the specific endpoint. FastAPI-Router leverages this file structure to seamlessly generate and map routes, providing an intuitive and efficient way to structure and manage API endpoints.

API Folder Structure

route.py

A route file enables the creation of customized request handlers for a specified route. It supports the following HTTP methods: GET, POST, PUT, PATCH, DELETE, HEAD, TRACE and OPTIONS.

def GET(): ...

def POST(): ...

def PUT(): ...

def PATH(): ...

def DELETE(): ...

def HEAD(): ...

def TRACE(): ...

def OPTIONS(): ...

By default, fastapi-router expects a folder named 'api' to exist. In case you need to change the name or have a project where you want to implement fastapi-router without that specific name, you can modify this by passing pathDir as an argument to the init_main_route function.

Example:

# For root folder
init_main_route(app, pathDir='app')

init_main_route(app2, pathDir='app/routes')

If the name 'route' doesn't suit you and you want to change it to another name to define the methods of the routes, you can pass nameRouteFile as an argument to the init_main_route function.

Example:

# Changing the route file name
init_main_route(app, nameRouteFile='methods')

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.