Documentation

Learn how to integrate DevApiHub ApiEndpoint and build amazing projects.

What is an API?

An API (Application Programming Interface) acts as a messenger between two applications. Think of it as a waiter in a restaurant: you (the client) ask for food (data), the waiter (API) takes your request to the kitchen (server), and brings the food back to you.

Example: When you check the weather on your phone, an API fetches that data from a weather server.

HTTP Methods (GET vs POST)

GET

Retrieve data from server.

POST

Send/Create new data to server.

PUT

Update or replace existing data.

PATCH

Partially update specific data.

DELETE

Remove data from server.

HEAD

Same as GET but without response body.

What is Fetch?

fetch() is a modern JavaScript method used to call an API. It allows you to make network requests to get data without refreshing the page.

// Using Async/Await (Modern Way)
const getExchangeRate = async () => {
  try {
    const response = await fetch('https://api.devapihub.com/v1/usd-to-bdt');
    const data = await response.json();
    console.log(data);
  } catch (error) {
    console.error("Error fetching data:", error);
  }
};

getExchangeRate();

Example Response

// Output: { "status": "success", "base": "USD", "target": "BDT", "rate": 121.45, "last_updated": "2024-05-20" }

HTTP Status Codes

Common responses you might receive from the API.

CodeStatusDescription
200OKRequest was successful.
201CreatedResource created successfully.
400Bad RequestInvalid request parameters.
401UnauthorizedInvalid or missing API key.
404Not FoundEndpoint not found.
500Server ErrorSomething went wrong on our end.