A simple Serverless Python API that generates a random 6-digit One-Time Password (OTP) and returns it in JSON format. It is designed to be lightweight and easily deployable using Vercel.
- Generates a random 6-digit OTP (e.g.,
123456). - Returns the OTP in a JSON response.
- Configured with CORS (
Access-Control-Allow-Origin: *) to be accessible from any frontend application. - Ready for Serverless deployment on Vercel.
When you make a GET request to the endpoint, it will return a JSON response containing the generated OTP.
Response format:
{
"otp": 583921
}To run the API locally on your machine for testing:
- Clone the repository and navigate to the project directory.
- Run the Python script:
python otp.py
- The server will start running at
http://localhost:8000/api/otp(or your root path). - You can visit
http://localhost:8000in your browser or usecurl/Postman to get an OTP.
This repository includes a vercel.json configuration file, making it ready to be deployed instantly on Vercel as a Serverless Function.
- Ensure you have the Vercel CLI installed, or link this repository to your Vercel dashboard.
- If using the CLI, simply run:
vercel
- Follow the prompts. The
vercel.jsonfile handles routing all requests to theotp.pyfunction.
This project is open-source and available under the MIT License.