10 API Integration code snippets

A shared folder with AI prompts and code snippets

From workspace: Replit

Team: AI Prompts

Total snippets: 7

Replit

10 API Integration code snippets

7 snippets

Use Python to Get Weather via API

Query weather data using requests and print the current temp.

import requests res = requests.get('https://api.weatherapi.com/v1/current.json', params={ 'key': 'your_api_key', 'q': 'Lisbon' }) data = res.json() print("Temp (°C):", data['current']['temp_c'])

Use Axios with Authorization Header

Send a GET request with a bearer token in Axios.

import axios from 'axios'; const token = 'your_api_token_here'; const res = await axios.get('https://api.example.com/data', { headers: { Authorization: `Bearer ${token}` } }); console.log(res.data);

Handle Webhook in Express

Create an Express route to receive and log incoming webhooks.

app.post('/webhook', express.json(), (req, res) => { const event = req.body; console.log('Webhook event received:', event.type); res.sendStatus(200); });

Submit Form Data to API in Python

Send a POST request with a JSON payload using the requests library.

import requests payload = {'email': 'test@example.com', 'password': '1234'} res = requests.post('https://api.example.com/login', json=payload) print(res.status_code, res.json())

Call OpenAI Chat API with Curl

Use Curl to make a POST request to OpenAI's chat completion API.

curl https://api.openai.com/v1/chat/completions \ -H "Authorization: Bearer $OPENAI_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "gpt-4", "messages": [{"role":"user", "content":"Hello!"}] }'

Use Supabase JS Client to Query Table

Query all rows from the 'profiles' table using Supabase client.

import { createClient } from '@supabase/supabase-js'; const supabase = createClient('https://xyz.supabase.co', 'public-anon-key'); const { data, error } = await supabase.from('profiles').select('*'); console.log(data);

Fetch Data from REST API with Axios

Use Axios to fetch and log data from a REST API endpoint.

import axios from 'axios'; async function getUsers() { try { const response = await axios.get('https://api.example.com/users'); console.log(response.data); } catch (error) { console.error('API error:', error.message); } }