Skip to content

Commit

Permalink
minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
s-bose committed Dec 1, 2023
1 parent 0124999 commit e1f7aad
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 9 deletions.
39 changes: 34 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,38 @@ Enable data validation for REST APIs.
Built on top of Pydantic and httpx.
Arrest is like a postman client for your microservice apis. It provides a simple layer of Pydantic encapsulation over Httpx HTTP calls to ensure structural integrity of your api definitions in a single file, as well as provide Pydantic's strength of data validation.

## TODOS
## Installation

- add logging support
- pretty print apispec + generate swagger docs
- config / setting option
- add database support
```bash
pip install arrest
```

## Getting Started

```python

from arrest.resource import Resource
from arrest.service import Service
from arrest.exceptions import ArrestHTTPException


xyz_service = Service(
name="xyz",
url="http://www.xyz-service.default.local.cluster:80",
resources=[
Resource(
route="/users",
handlers=[
("GET", "/"),
("GET", "/{user_id:int}"),
("POST", "/")
]
)
]
)

try:
response = await xyz_service.users.get("/123")
except ArrestHTTPException as exc:
logging.warning(f"{exc.status_code} {exc.data}")
```
6 changes: 3 additions & 3 deletions arrest/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ class ArrestError(BaseException):
"""used in error situations"""


class ArrestHTTPException(BaseException):
class ArrestHTTPException(ArrestError):
def __init__(self, status_code: int, data: dict | str) -> None:
self.status_code = status_code
self.data = data


class NotFoundException(BaseException):
class NotFoundException(ArrestError):
def __init__(self, message: str):
self.message = message


class HandlerNotFound(NotFoundException):
class HandlerNotFound(ArrestError):
pass
2 changes: 1 addition & 1 deletion arrest/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ async def request(
match := self.get_matching_handler(method=method, url=url, **kwargs)
):
logger.warning("no matching handler found for request")
raise HandlerNotFound(message="no matching handler found for request")
raise HandlerNotFound("no matching handler found for request")

handler, url = match

Expand Down
12 changes: 12 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ description = "Arrest is a wrapper of pydantic and httpx to make your REST api c
authors = ["shiladitya <[email protected]>"]
license = "MIT"
readme = "README.md"
homepage = "https://github.com/s-bose/arrest"
repository = "https://github.com/s-bose/arrest"
documentation = "https://github.com/s-bose/arrest"
keywords = ["arrest", "rest", "pydantic", "httpx", "api"]
classifiers = [
"Natural Language :: English",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Software Development :: Libraries",
]

[tool.poetry.dependencies]
python = "^3.10"
Expand Down

0 comments on commit e1f7aad

Please sign in to comment.