semvec/pypi-packages huggingface dataset:
fastapi-yaml 0.3.0rc0
Handle YAML data in FastAPI
License: MIT
Requires Python: >=3.11

# Overview

Handle YAML requests with FastAPI.
The package will do the best effort to convert the YAML request to JSON.
All files that are uploaded as multipart/form-data will be concatenated and converted to JSON if the header `handle-as-yaml` is set to true.

# Installation

```bash
pip install fastapi-yaml
```

# Usage

FastAPI Code:

```python
from fastapi import FastAPI
from fastapi_yaml import YamlRoute
from pydantic import BaseModel

app = FastAPI()
app.router.route_class = YamlRoute

class Person(BaseModel, extra='forbid'):
    name: str
    age: int

@app.post("/person")
def person(person: Person):
    return f"{person.name} is {person.age} years old"
```

HTTP Request:

```bash
curl --request POST \
  --url http://localhost:8000/person \
  --header "content-type: application/x-yaml" \
  --data "name: John Doe\nage: 42"
```

# Tests

```bash
poetry run pytest --cov fastapi_yaml tests/
```

## Coverage

```text
---------- coverage: platform darwin, python 3.11.2-final-0 ----------
Name                       Stmts   Miss  Cover
----------------------------------------------
fastapi_yaml/__init__.py       1      0   100%
fastapi_yaml/main.py          20      0   100%
----------------------------------------------
TOTAL                         21      0   100%
```