Skip to main content

Moschitta Routing Documentation

The moschitta-routing package provides a simple and flexible routing system for the Moschitta Framework, allowing developers to define and handle HTTP routes easily.

Installation

You can install moschitta-routing via pip:

pip install moschitta-routing

Or use it with Poetry:

poetry add moschitta-routing

Usage

Creating Routes

Routes are created using the provided decorators (@GET, @POST, @PUT, @PATCH, @DELETE, @OPTIONS, @HEAD, @CONNECT, @TRACE) and registered with the router.

from moschitta_routing import GET, POST

@GET('/users')
def get_users(request):
    # Handler logic to retrieve users
    return [{"id": 1, "name": "John"}, {"id": 2, "name": "Alice"}]

@POST('/users')
def create_user(request):
    # Handler logic to create a new user
    return {"message": "User created successfully"}

Handling Requests

Handlers are simple functions that take a request object as input and return a JSON response. You can access request parameters within the handler function.

def get_users(request):
    # Handler logic to retrieve users
    return [{"id": 1, "name": "John"}, {"id": 2, "name": "Alice"}]

Running the Router

After defining routes and handlers, you can run the router to handle incoming HTTP requests.

from moschitta_routing.router import Router

router = Router()

# Add routes here using the provided decorators

if __name__ == "__main__":
    # Run the router
    router.run(host='0.0.0.0', port=8000)

API Reference

moschitta_routing.router.Router

  • add_route(path: str, method: str, handler: Callable[[Any], Any]) -> None: Adds a new route to the router.
  • get(path: str, method: str = 'GET') -> Optional[Callable[[Any], Any]]: Retrieves the handler function associated with a specific route.
  • __len__() -> int: Returns the total number of routes currently defined in the router.
  • __iter__(): Allows iterating over all registered route paths in the router.

Decorators

  • @GET(path: str) -> Callable: Decorator for handling GET requests.
  • @POST(path: str) -> Callable: Decorator for handling POST requests.
  • @PUT(path: str) -> Callable: Decorator for handling PUT requests.
  • @PATCH(path: str) -> Callable: Decorator for handling PATCH requests.
  • @DELETE(path: str) -> Callable: Decorator for handling DELETE requests.
  • @OPTIONS(path: str) -> Callable: Decorator for handling OPTIONS requests.
  • @HEAD(path: str) -> Callable: Decorator for handling HEAD requests.
  • @CONNECT(path: str) -> Callable: Decorator for handling CONNECT requests.
  • @TRACE(path: str) -> Callable: Decorator for handling TRACE requests.

Contributing

Contributions to moschitta-routing are welcome! You can contribute by opening issues for bugs or feature requests, submitting pull requests, or helping improve the documentation.

License

This project is licensed under the MIT LICENSE.

Release files for moschitta-routing 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for moschitta-routing 0.1.1
File Size Uploaded
moschitta_routing-0.1.1.tar.gz 4.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for moschitta-routing 0.1.1
File Interpreter ABI Platform
moschitta_routing-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 8.8 kB

Release files / moschitta_routing-0.1.1.tar.gz

Download URL moschitta_routing-0.1.1.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
c2559593a2f32bbc9f0738376a8a61d0e28cb92614fe525d0b8f6ac1b30cdd35
BLAKE2b-256 checksum
How to use checksums
a053aea08e861f92fe168c8ff37289ae107cd53f08af1480ec11138d1a2adc58
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.2 CPython/3.11.2 Linux/6.5.0-13parrot1-amd64

Release files / moschitta_routing-0.1.1-py3-none-any.whl

Download URL moschitta_routing-0.1.1-py3-none-any.whl
Size 4.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9182708ed062660474134a9eadeef15a3d148104e19d4a59cd872608c25ee448
BLAKE2b-256 checksum
How to use checksums
a63ae924c18627600471e8d9f5ef675ad40746cecacb790ecb2049f484fedadd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.3.2 CPython/3.11.2 Linux/6.5.0-13parrot1-amd64

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page