This is a simple Flask application that provides a random joke through an API using the Pyjokes library. The application includes routes for documentation and fetching a joke, with proper error handling.
- Redirects:
/redirects to/docs/./joke/redirects to/joke.
- Documentation:
/docsand/docs/provide information about the available routes.
- Random Joke:
/jokereturns a random joke in JSON format using thepyjokeslibrary. It accepts an optionallangparameter to specify the language of the joke.
- Python 3.x
- Flask
- pyjokes
-
Clone the repository:
git clone https://github.com/Ahmedallion/pyjokes-api.git cd pyjokes-api -
Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install the required packages:
pip install flask pyjokes
-
Start the Flask server:
python app.py
-
Access the application:
- Open a web browser and navigate to
http://127.0.0.1:5000/.
- Open a web browser and navigate to
- Root:
/- Redirects to the documentation page.
- Documentation:
/docsor/docs/- Provides information about the available routes.
- Joke:
/joke- Returns a random joke in JSON format. Accepts an optional
langparameter to specify the language of the joke.
- Returns a random joke in JSON format. Accepts an optional
- Joke Redirect:
/joke/- Redirects to
/joke.
- Redirects to
-
Documentation (
GET /docs):{ "routes": { "/": { "description": "Redirects to the docs page." }, "/docs": { "description": "Shows the routes for this API." }, "/joke": { "description": "Tells a random joke.", "parameters": { "lang": { "description": "Specifies the language of the joke.", "valid_options": "'en', 'de', 'es', 'gl', 'eu'', 'it'" } } } } } -
Random Joke (
GET /joke):{ "joke": "Ubuntu users are apt to get this joke." }
