Skip to main content
Version: Next

API

Let's check Textgrader API in 5 minutes.

API Endpoints

Textgrader API is a simple FastAPI project with 3 endpoints:

Base Endpoint

This endpoint just return a message reporting that the API is ok, the code is highlighted bellow:

backend/src/api.py
class Request(BaseModel):
essay: str

@app.get("/")
def home():
response = {
"message": "Text Grade API OK! For help go to /docs endpoint."
}

return response

@app.post("/text_grade/")
async def text_grade(request: Request) -> dict[str, int]:
response = {
"grade": predict_from_text(request.essay)
}

return response

Text Grade Endpoint

This is the API main endpoint, this endpoints call predict_from_text function handles giving grades to essays on real time. This endpoint has a Requestclass that makes the API call validation and reports for the client what kind of data and format he needs to use. This endpoint is highlighted in the code bellow:

backend/src/api.py
class Request(BaseModel):
essay: str

@app.get("/")
def home():
response = {
"message": "Text Grade API OK! For help go to /docs endpoint."
}

return response

@app.post("/text_grade/")
async def text_grade(request: Request) -> dict[str, int]:
response = {
"grade": predict_from_text(request.essay)
}

return response