|
|
# Since we care about maintainability, lets do a bit of housework |
|
|
\ No newline at end of file |
|
|
# Its time we gave this service a face
|
|
|
|
|
|
While FastAPI is brilliant at building API's, it is also able to build self-contained micro-services that incorporate more than just data and business logic, it can exist as a sort of micro-site in it self.
|
|
|
|
|
|
## Content + Style == Success
|
|
|
|
|
|
Usually, the frontpage of a site (index.html), doesn't return JSON data.
|
|
|
So lets change that first.
|
|
|
|
|
|
Remove the function `read_root()` and its body, the `return {"Hello": "World"}`
|
|
|
Replace it with the following code
|
|
|
|
|
|
```python
|
|
|
@app.get("/")
|
|
|
async def index():
|
|
|
content: str = """
|
|
|
<html>
|
|
|
<body>
|
|
|
<h1>Hello world</1>
|
|
|
</body>
|
|
|
</html>
|
|
|
"""
|
|
|
|
|
|
return HTMLResponse(content)
|
|
|
```
|
|
|
|
|
|
And add the following import to the top `from fastapi.responses import HTMLResponse`
|
|
|
|
|
|
There are many response classes in FastAPI, and in this case we make use of its HTML response.
|
|
|
|
|
|
You know the drill, save `:w` and navigate to your services frontpage: [fastapi.ibmi.rocks](https://fastapi.ibmi.rocks)
|
|
|
|
|
|
## Since we care about maintainability, lets do a bit of housework
|
|
|
|
|
|
First, API's can grow large containing many endpoints, having them all in one file is silly.
|
|
|
A bit of refactoring can go a long way, but |
|
|
\ No newline at end of file |