Skip to main content

No project description provided

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

moschitta_routing-0.1.1.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

moschitta_routing-0.1.1-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file moschitta_routing-0.1.1.tar.gz.

File metadata

  • Download URL: moschitta_routing-0.1.1.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.11.2 Linux/6.5.0-13parrot1-amd64

File hashes

Hashes for moschitta_routing-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c2559593a2f32bbc9f0738376a8a61d0e28cb92614fe525d0b8f6ac1b30cdd35
MD5 a1c56118622cb3b473f7fa539a2285e2
BLAKE2b-256 a053aea08e861f92fe168c8ff37289ae107cd53f08af1480ec11138d1a2adc58

See more details on using hashes here.

File details

Details for the file moschitta_routing-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: moschitta_routing-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.11.2 Linux/6.5.0-13parrot1-amd64

File hashes

Hashes for moschitta_routing-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9182708ed062660474134a9eadeef15a3d148104e19d4a59cd872608c25ee448
MD5 7bac3d3e1a37418117a2b88258cc8981
BLAKE2b-256 a63ae924c18627600471e8d9f5ef675ad40746cecacb790ecb2049f484fedadd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page