REST API Examples

Working code examples using free public APIs. Copy, paste, and run - no API keys required.

8+Examples
3Languages
FreeNo API Key
Browse All APIs →

HTTP Methods Quick Reference

MethodPurposeExampleHas Body
GETRetrieve dataFetch user profileNo
POSTCreate new resourceCreate new userYes
PUTUpdate entire resourceUpdate user profileYes
PATCHPartial updateUpdate user email onlyYes
DELETERemove resourceDelete user accountNo

REST API Examples by Category

Each example includes working code in JavaScript (fetch), Python (requests), and cURL. All APIs listed below are free and do not require authentication for basic usage.

Open-Meteo Weather API

Weather
View API Details →

Free weather API with no API key required. Get current weather, forecasts, and historical data.

https://api.open-meteo.com/v1/forecast
JavaScript
// Get current weather for Berlin
const response = await fetch(
  'https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41&current_weather=true'
);
const data = await response.json();
console.log(data.current_weather);
// { temperature: 15.3, windspeed: 12.5, weathercode: 3 }
Example Response:
Response
{
  "current_weather": {
    "temperature": 15.3,
    "windspeed": 12.5,
    "winddirection": 220,
    "weathercode": 3,
    "time": "2026-01-09T12:00"
  }
}

JSONPlaceholder

Testing
View API Details →

Free fake REST API for testing and prototyping. Perfect for learning HTTP methods.

https://jsonplaceholder.typicode.com
JavaScript
// GET - Fetch all posts
const posts = await fetch('https://jsonplaceholder.typicode.com/posts')
  .then(res => res.json());

// POST - Create a new post
const newPost = await fetch('https://jsonplaceholder.typicode.com/posts', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    title: 'My Post',
    body: 'This is the content',
    userId: 1
  })
}).then(res => res.json());

// PUT - Update a post
const updated = await fetch('https://jsonplaceholder.typicode.com/posts/1', {
  method: 'PUT',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({
    id: 1,
    title: 'Updated Title',
    body: 'Updated content',
    userId: 1
  })
}).then(res => res.json());

// DELETE - Remove a post
await fetch('https://jsonplaceholder.typicode.com/posts/1', {
  method: 'DELETE'
});
Example Response:
Response
{
  "id": 101,
  "title": "My Post",
  "body": "This is the content",
  "userId": 1
}

CoinGecko API

Cryptocurrency
View API Details →

Free cryptocurrency API for prices, market data, and coin information.

https://api.coingecko.com/api/v3
JavaScript
// Get Bitcoin price in USD
const response = await fetch(
  'https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd'
);
const data = await response.json();
console.log("Bitcoin: $" + data.bitcoin.usd);

// Get top 10 coins by market cap
const coins = await fetch(
  'https://api.coingecko.com/api/v3/coins/markets?vs_currency=usd&order=market_cap_desc&per_page=10'
).then(res => res.json());
Example Response:
Response
{
  "bitcoin": {
    "usd": 42150
  }
}

Random User API

Testing
View API Details →

Generate random user data for testing. Get names, emails, addresses, and profile pictures.

https://randomuser.me/api
JavaScript
// Get a random user
const response = await fetch('https://randomuser.me/api/');
const data = await response.json();
const user = data.results[0];
console.log(user.name.first + " " + user.name.last);
console.log(user.email);

// Get 5 US users
const usUsers = await fetch('https://randomuser.me/api/?results=5&nat=us')
  .then(res => res.json());
Example Response:
Response
{
  "results": [
    {
      "name": {
        "first": "John",
        "last": "Smith"
      },
      "email": "john.smith@example.com",
      "picture": {
        "large": "https://randomuser.me/api/portraits/men/1.jpg"
      }
    }
  ]
}

IP-API Geolocation

Geolocation
View API Details →

Free IP geolocation API. Get country, city, timezone, and ISP from any IP address.

http://ip-api.com/json
JavaScript
// Get location from IP
const response = await fetch('http://ip-api.com/json/');
const data = await response.json();
console.log("Location: " + data.city + ", " + data.country);

// Lookup specific IP
const ipData = await fetch('http://ip-api.com/json/8.8.8.8')
  .then(res => res.json());
console.log("Google DNS is in " + ipData.city);
Example Response:
Response
{
  "status": "success",
  "country": "United States",
  "city": "Mountain View",
  "lat": 37.3861,
  "lon": -122.0839,
  "isp": "Google LLC"
}

Free Pokemon API with data on all Pokemon, moves, abilities, and more.

https://pokeapi.co/api/v2
JavaScript
// Get Pikachu data
const response = await fetch('https://pokeapi.co/api/v2/pokemon/pikachu');
const pokemon = await response.json();
const types = pokemon.types.map(t => t.type.name).join(", ");
console.log(pokemon.name + ": " + types);
// pikachu: electric

// Get all Pokemon (paginated)
const allPokemon = await fetch('https://pokeapi.co/api/v2/pokemon?limit=20')
  .then(res => res.json());
Example Response:
Response
{
  "name": "pikachu",
  "id": 25,
  "types": [
    {
      "type": {
        "name": "electric"
      }
    }
  ],
  "stats": [
    {
      "base_stat": 35,
      "stat": {
        "name": "hp"
      }
    }
  ]
}

Cat Facts API

Animals
View API Details →

Get random cat facts. Simple API perfect for beginners.

https://catfact.ninja
JavaScript
// Get a random cat fact
const response = await fetch('https://catfact.ninja/fact');
const data = await response.json();
console.log(data.fact);
// "Cats sleep 70% of their lives."
Example Response:
Response
{
  "fact": "Cats sleep 70% of their lives.",
  "length": 31
}

Predict age from a name using AI. Fun API for learning.

https://api.agify.io
JavaScript
// Predict age from name
const response = await fetch('https://api.agify.io?name=michael');
const data = await response.json();
console.log(data.name + ": predicted age " + data.age);
// michael: predicted age 58
Example Response:
Response
{
  "name": "michael",
  "age": 58,
  "count": 233482
}

Error Handling Best Practices

Always handle errors when making API calls. Here is a robust pattern:

JavaScript
async function fetchApi(url) {
  try {
    const response = await fetch(url);

    // Check if response is OK (status 200-299)
    if (!response.ok) {
      throw new Error("HTTP error! Status: " + response.status);
    }

    const data = await response.json();
    return data;
  } catch (error) {
    if (error.name === 'TypeError') {
      console.error('Network error - check your connection');
    } else {
      console.error('API error:', error.message);
    }
    throw error;
  }
}

// Usage
try {
  const data = await fetchApi('https://api.example.com/data');
  console.log(data);
} catch (error) {
  // Handle error in UI
}

Frequently Asked Questions

What is a REST API example?

A REST API example is working code that demonstrates how to make HTTP requests (GET, POST, PUT, DELETE) to a web service. REST APIs use standard HTTP methods to create, read, update, and delete data. For example, fetching weather data with fetch('https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41') is a REST API call.

What are the 4 types of REST API calls?

The 4 main types of REST API calls are: GET (retrieve data), POST (create new data), PUT (update existing data), and DELETE (remove data). These correspond to CRUD operations: Create, Read, Update, Delete. GET requests fetch information, POST sends new data to the server, PUT modifies existing resources, and DELETE removes them.

What is an example of an API request?

An API request is a call to a web service endpoint. For example, in JavaScript: fetch('https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd'). This GET request asks CoinGecko's API for Bitcoin's current USD price. The response returns JSON data like {"bitcoin":{"usd":42000}}.

How do I test a REST API?

You can test REST APIs using: 1) cURL in the terminal (curl https://api.example.com/data), 2) Browser fetch in DevTools console, 3) Tools like Postman or Insomnia, 4) Code in JavaScript (fetch) or Python (requests library). Many public APIs like JSONPlaceholder are designed specifically for testing.

What are free public APIs I can use?

Popular free public APIs include: Open-Meteo (weather), CoinGecko (cryptocurrency), PokeAPI (Pokemon data), JSONPlaceholder (testing), Random User (fake user data), and Cat Facts. PublicAPIs.io lists over 1000 free APIs across categories like weather, finance, games, and more.

Explore More Free APIs

PublicAPIs.io has over 1,000 free public APIs across 50+ categories. Find the perfect API for your next project.