This module defines a simple FastAPI application with one main API endpoint. The purpose of this endpoint is to retrieve information about a user associated with the HNG program based on their Slack name and track.
- URL:
/api
- HTTP Method: GET
slack_name
(str): The Slack name of the user.track
(str): The track the user is in.
GET /api?slack_name=johndoe&track=backend
- Status Code: 200 OK
- Content-Type: application/json
{
"slack_name": "johndoe",
"current_day": "Wednesday",
"utc_time": "2023-09-06T12:34:56Z",
"track": "backend",
"github_file_url": "https://github.com/Cofucan/simple_fastapi_endpoint/blob/main/main.py",
"github_repo_url": "https://github.com/Cofucan/simple_fastapi_endpoint",
"status_code": 200
}
This endpoint allows you to retrieve information about an HNG user.
It expects two query parameters: slack_name
and track
.
After receiving the parameters, it returns a JSON response containing the following information:
slack_name
: The Slack name of the user.current_day
: The current day of the week in UTC time.utc_time
: The current UTC time in the format "YYYY-MM-DDTHH:MM:SSZ".track
: The track the user is in.github_file_url
: URL to the main.py file of this FastAPI application on GitHub.github_repo_url
: URL to the GitHub repository of this FastAPI application.status_code
: The HTTP status code, which will always be 200 for successful requests.
To run this FastAPI application locally, follow these steps:
-
Clone the GitHub repository:
git clone https://github.com/Cofucan/simple_fastapi_endpoint.git
-
Install the required dependencies using pip or pip3:
pip install -r requirements.txt
-
Change directory to the project folder:
cd simple_fastapi_endpoint
-
Run the application using Uvicorn:
uvicorn main:app --reload
The API will be available at http://localhost:8000.
There are a few unit tests available, implemented using pytest
. You can run the tests using:
pytest