This project is a FastAPI application that allows users to submit form data, which is then stored in a MongoDB Atlas database. The API supports full CRUD operations (Create, Read, Update, Delete) and is designed to be deployed on Render with automatic deployments from GitHub.
- FastAPI for creating the API endpoints.
- MongoDB Atlas for storing form data.
- Motor for asynchronous MongoDB operations.
- Pydantic for data validation.
- Environment variable management for sensitive data.
- typeform-backend/
- │
- ├── app/
- │ ├── init.py
- │ ├── main.py
- │ ├── models.py
- │ ├── database.py
- │ └── routes/
- │ └── form.py
- ├── .env
- ├── .gitignore
- ├── requirements.txt
- └── README.md
- Python 3.7+
- MongoDB Atlas account
-
Clone the repository:
git clone https://github.com/your-username/typeform-backend.git cd typeform-backend
-
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables:
-
Create a .env file in the root directory of your project and add your MongoDB connection string:
MONGO_DETAILS=mongodb+srv://<username>:<password>@<cluster-address>/typeform?retryWrites=true&w=majority
-
Note: Replace
<username>
,<password>
, and<cluster-address>
with your actual MongoDB Atlas credentials.
-
-
Run the application:
uvicorn app.main:app --reload
You can use Postman or any other API client to interact with the API. Below are the endpoints available:
-
URL:
http://localhost:8000/api/form
-
Method: POST
-
Headers:
Content-Type: application/json
-
Body: (JSON)
{ "first_name": "John", "last_name": "Doe", "email": "[email protected]", "country": "USA", "phone_number": "+1234567890", "languages": ["Python", "JavaScript"], "experience_level": "Intermediate", "compensation": "$50,000 - $80,000", "certifying_statement": "I accept", "linkedin_url": "https://www.linkedin.com/in/johndoe" }
- URL:
http://localhost:8000/api/forms
- Method: GET
- URL:
http://localhost:8000/api/form/{id}
- Method: GET
- URL:
http://localhost:8000/api/form/{id}
- Method: PUT
- Headers:
Content-Type: application/json
- Body: (JSON)
{ "first_name": "Jane", "last_name": "Doe", "email": "[email protected]", "country": "Canada", "phone_number": "+9876543210", "languages": ["Rust", "C++"], "experience_level": "Advanced", "compensation": "$80,000 - $120,000", "certifying_statement": "I accept", "linkedin_url": "https://www.linkedin.com/in/janedoe" }
- URL:
http://localhost:8000/api/form/{id}
- Method: DELETE
- Ensure your MongoDB connection string is correct.
- Verify that your MongoDB Atlas cluster is accessible and IP whitelisted.
- Check the logs for any deployment issues.
https://typeform-backend.onrender.com