Initial fastapi structure.#94
Conversation
| app = FastAPI() | ||
|
|
||
| # Constants | ||
| HTTP_OK = 200 |
There was a problem hiding this comment.
Let's use the existing definitions https://fastapi.tiangolo.com/tutorial/response-status-code/#shortcut-to-remember-the-names
| HTTP_OK = 200 | |
| from fastapi.status import HTTP_200_OK |
| for i in range(2): | ||
| for perp in [False, True]: | ||
| r = await http_client.get(f"http://{other_node_address}/chsh/set_basis?i={i}&perp={perp}") | ||
| if r.status_code != HTTP_OK: |
There was a problem hiding this comment.
| if r.status_code != HTTP_OK: | |
| TODO: Handle other status codes | |
| if r.status_code != HTTP_200_OK: |
| "fastapi[standard]>=0.115.14", | ||
| "httpx>=0.28.1", |
There was a problem hiding this comment.
Is there any case where someone might want to use this package without the api? If so, we should put these dependencies in an optional "webapp" dependency group so they aren't forced to download code they won't use. https://docs.astral.sh/uv/concepts/projects/dependencies/#optional-dependencies
| @app.get("/chsh/set_basis") | ||
| async def request_basis(i: int, *, perp: bool) -> bool: | ||
| angle = state.chsh_basis[i] + 90 * perp | ||
| logger.info("moving waveplate", extra={"angle": angle}) | ||
| return True |
There was a problem hiding this comment.
State is changing, so this should be a POST request. I'm also thinking ahead to possibly having other methods for setting the basis.
| @app.get("/chsh/set_basis") | |
| async def request_basis(i: int, *, perp: bool) -> bool: | |
| angle = state.chsh_basis[i] + 90 * perp | |
| logger.info("moving waveplate", extra={"angle": angle}) | |
| return True | |
| @app.post("/chsh/request-angle-by-basis") | |
| async def request_angle_by_basis(id:int, *, perp: bool = False) -> bool: | |
| angle = state.chsh_basis[id] + 90 * perp | |
| logger.info("moving waveplate", extra={"angle": angle}) | |
| return True |
Co-authored-by: Benjamin Nussbaum <50522055+Benjamin-Nussbaum@users.noreply.github.com>
SoroushHoseini
left a comment
There was a problem hiding this comment.
It looks good to merge for me.
We started from a more bare-bones approach based on the webapp branch. The goal is to move fast an get a real chsh measurement. The plan is to make it more robust and better practices as needed in future PRs.