https://github.com/stanmiglight/lab1
This FastAPI service handles a user database with CRUD operations for users identified by user_id and name.
https://github.com/stanmiglight/lab1
fastapi python school-project
Last synced: about 2 months ago
JSON representation
This FastAPI service handles a user database with CRUD operations for users identified by user_id and name.
- Host: GitHub
- URL: https://github.com/stanmiglight/lab1
- Owner: stanmiglight
- Created: 2024-09-29T07:47:03.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-30T04:22:55.000Z (over 1 year ago)
- Last Synced: 2025-04-02T08:16:37.699Z (about 1 year ago)
- Topics: fastapi, python, school-project
- Language: Python
- Homepage:
- Size: 13.8 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Factorial Calculator API
This is a simple FastAPI-based web service that calculates the factorial of a given integer. The API provides an endpoint where you can send a number, and it will return the factorial of that number.
## Features
- **FastAPI**: A modern, fast (high-performance) web framework for building APIs with Python 3.7+ based on standard Python type hints.
- **Factorial Calculation**: The API calculates the factorial of a given integer using a while loop.
- **Error Handling**: If the input number is 0, the API returns `{ "result": false }` since the factorial of 0 is not defined in this implementation.
## Installation
### Clone the repository:
```bash
git clone https://github.com/yourusername/factorial-api.git
cd factorial-api
```
### Set up a virtual environment (optional but recommended):
```bash
python -m venv venv
source venv/bin/activate # On Windows use `venv\Scripts\activate`
```
### Install dependencies:
```bash
pip install fastapi uvicorn
```
### Run the application:
```bash
uvicorn main:app --reload
```
The `--reload` flag enables auto-reloading, so the server will restart whenever you make changes to the code.
## Usage
Once the server is running, you can access the API at [http://127.0.0.1:8000](http://127.0.0.1:8000).
### Endpoint
`GET /factorial/{starting_number}`: Calculates the factorial of the provided integer.
#### Example Request:
```bash
curl -X GET "http://127.0.0.1:8000/factorial/5"
```
#### Example Response:
```json
{
"result": 120
}
```
#### Example Request for 0:
```bash
curl -X GET "http://127.0.0.1:8000/factorial/0"
```
#### Example Response:
```json
{
"result": false
}
```
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
## Acknowledgments
- **Sir Paulo** for the idea!
- **FastAPI** for providing an easy-to-use and high-performance web framework.
- **Python** for being awesome.