LLM Prompts

API Integration Code Generation

Generates code snippets for interacting with APIs.

The method

Use this prompt by providing a specific API endpoint, desired programming language, and a description of the functionality you want to achieve. Paste it directly into your LLM’s chat interface. It works best when you have a clear understanding of the API’s documentation.

The prompts

Prompt 1
Generate a Python function that retrieves data from the SpaceX API's `/launches/upcoming` endpoint and prints the name and launch date of the next 5 upcoming launches. Include error handling for network issues and invalid JSON responses. The function should also include docstrings explaining its purpose, arguments, and return value. Make sure the code is well-formatted and easy to read. Also suggest any required Python libraries or modules.
Prompt 2
Write a JavaScript function using `fetch` that authenticates with the GitHub API using a personal access token (stored securely as an environment variable `GITHUB_TOKEN`) and then retrieves the 10 most recent commits from the specified repository (`owner/repo`). Format the commit messages and author names into an HTML unordered list and display it in the element with the ID `commit-list`. Include comments explaining each step of the process. Ensure the function handles rate limiting by checking the `X-RateLimit-Remaining` header and displaying a message if the limit is approaching. Consider using `async/await` for cleaner asynchronous code. Also, provide a basic HTML structure with the `commit-list` element.
Prompt 3
Create a PHP script that connects to the OpenWeatherMap API using the city name provided as an argument. Retrieve the current weather conditions (temperature, humidity, wind speed, and description) and display them in a user-friendly format. Implement caching to avoid exceeding the API's rate limit. Store the cached data in a file for a maximum of 1 hour. Include appropriate error handling and logging. Ensure that the script uses proper API key management by storing the API key in a separate configuration file (e.g., `config.php`) and accessing it securely. Also display the weather icon.