Skip to content

Commit

Permalink
add example to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
s-bose committed Nov 1, 2024
1 parent 9f23500 commit e167a37
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ This gets automatically validated and parsed as `UserRequest` before sending the
Similar to request, you can pass an additional fourth argument in the handler tuple for specifying a pydantic model for the handler.
If provided it will automatically deserialize the returned success json response into either a model instance or a list of model instances.


## Examples

```python
class UserResponse(BaseModel):
name: str
Expand All @@ -140,6 +137,21 @@ Here, the JSON response from `https://www.xyz-service.default.local.cluster/api/

For more info, please check the [docs](https://s-bose.github.io/arrest/getting-started)

## Examples

You can check out the `example` folder under the project repository to get a feel of how to use Arrest.

The `example_service` contains a minimal FastAPI application for task management with CRUD endpoints for `users` and `tasks`.

To generate the Arrest boilerplate from the OpenAPI specs, simply run the FastAPI application using `uvicorn` at [http://127.0.0.1:8080/docs](), and run the arrest CLI as followed:

```bash
$ arrest -u http://localhost:8080/openapi.json -d example_service
```
This will generate `models.py`, containing the Pydantic schemas corresponding to the OpenAPI components, a `resources.py` containing the RESTful resource definitions and a `services.py` containing the service definition that includes the resources.

To use the service, simply call `example_service.users.get("")`.


## Contributing

Expand Down
11 changes: 10 additions & 1 deletion docs/examples.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
You can refer to the `example` folder for different use cases.

It comes with a completely functional REST API suite for task management with CRUD operations for `users` and `tasks`.
The `example_service` contains a minimal FastAPI application for task management with CRUD endpoints for `users` and `tasks`.

It uses in-memory dictionaries for data storage, so of course this is just for testing and learning purposes.

Expand All @@ -22,6 +22,15 @@ To run the example FastAPI application, simply go to the example directory at th

Alternatively, you can set up your own virtualenv, and install the `requirements.example.txt` and run `uvicorn app.main:app`.

To generate the Arrest boilerplate from the OpenAPI specs, simply run the FastAPI application using `uvicorn` at [http://127.0.0.1:8080/docs](), and run the arrest CLI as followed:

```bash
$ arrest -u http://localhost:8080/openapi.json -d example_service
```
This will generate `models.py`, containing the Pydantic schemas corresponding to the OpenAPI components, a `resources.py` containing the RESTful resource definitions and a `services.py` containing the service definition that includes the resources.

To use the service, simply call `example_service.users.get("")`.


## Running Tests

Expand Down

0 comments on commit e167a37

Please # to comment.