""" Copyright (c) 2023 Grader Than Technology LLC. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Description: This is a HTTP Rest API build with python FastAPI, that demonstrates how to create a simple API that accepts GET and POST requests. The service is a note taking application that allows a user to save notes with POST requests and retrieve notes with GET requests. Usage: (It's assumed you are running the application from a GT Workspace) Run the server - `uvicorn main:app --reload` Save a note - `curl -X POST "http://localhost:8000/notes/" -H "Content-Type: application/json" -d '{"title": "joke", "content": "What do you call a bear with no teeth? A gummy bear"}'` Retrieve a note - `curl http://localhost:8000/notes/joke` Author: Harris Williams """ import json from typing import Optional from fastapi import FastAPI from pydantic import BaseModel app = FastAPI() class NoteCreate(BaseModel): title: str content: str @app.post("/notes/") async def create_note(note: NoteCreate): with open("notes.txt", "a+") as f: f.write(json.dumps(note.dict()) + "\n") return {"status": "Note created"} @app.post("/notes/") async def create_note(note: NoteCreate): with open("notes.txt", "a+") as f: f.write(json.dumps(note.dict()) + "\n") return {"status": "Note created"}