REST API Basics for Developers: Methods, Status Codes and JSON Explained

Most modern web services, including our recharge, bill payment and verification APIs, follow the REST style. If you are new to API work, or you have been copying snippets without being sure why they work, this guide covers the essentials you need for real integrations.

What REST means in practice

REST (Representational State Transfer) is a way of designing APIs around resources (things like a transaction, a bill or a customer) that you reach through URLs, using the standard methods of HTTP, the same protocol your browser uses. You do not need to memorise the theory. In daily work, REST means:

  • Each resource has a clear URL, such as /api/services/v1/recharge/status.
  • You use HTTP methods to say what you want to do.
  • Data goes back and forth as JSON.
  • The HTTP status code tells you, at a glance, whether the request worked.
  • Each request carries everything needed to process it; the server does not remember your previous call.

HTTP methods

MethodTypical useSafe to repeat?
GETRead data, such as balance or transaction statusYes
POSTCreate something, such as a new recharge or verificationNot by default
PUT / PATCHUpdate an existing recordPUT usually yes; PATCH depends
DELETERemove a recordUsually yes

"Safe to repeat" matters a great deal for money APIs. Retrying a GET is harmless; retrying a POST that creates a recharge could charge twice unless the API supports idempotency keys.

Anatomy of a request

  • URL (endpoint): where the request goes, for example https://www.pepploweb.com/api/services/v1/recharge.
  • Method: POST, GET and so on.
  • Headers: metadata such as Content-Type: application/json and your API key.
  • Body: the JSON data, for methods that send data.

Status codes you will meet most

  • 200 OK – the request was processed. Still read the body: a recharge can be "accepted" but pending.
  • 201 Created – a new record was created.
  • 400 Bad Request – something in your input is wrong.
  • 401 Unauthorized / 403 Forbidden – missing or wrong key, or a request from a non-whitelisted IP.
  • 404 Not Found – wrong URL or unknown record.
  • 409 Conflict – often a duplicate reference.
  • 422 Unprocessable Entity – the format is fine but a value fails validation.
  • 429 Too Many Requests – you hit a rate limit; slow down.
  • 500–504 – a server or gateway problem; the outcome may be unknown.

The same call in three languages

These examples check a wallet balance. The endpoint and header names are illustrative; always follow the exact fields in our API documentation.

PHP (cURL)

$ch = curl_init('https://www.pepploweb.com/api/services/v1/balance');
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT        => 20,
    CURLOPT_HTTPHEADER     => ['Authorization: Bearer YOUR_API_KEY', 'Accept: application/json'],
]);
$body   = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
$data = json_decode($body, true);

JavaScript (Node.js 18+)

const res = await fetch('https://www.pepploweb.com/api/services/v1/balance', {
  headers: { Authorization: 'Bearer YOUR_API_KEY', Accept: 'application/json' },
  signal: AbortSignal.timeout(20000),
});
const data = await res.json();
console.log(res.status, data);

Python (requests)

import requests
r = requests.get(
    "https://www.pepploweb.com/api/services/v1/balance",
    headers={"Authorization": "Bearer YOUR_API_KEY", "Accept": "application/json"},
    timeout=20,
)
print(r.status_code, r.json())

Reading JSON responses carefully

A typical response contains a machine-readable status, a human-readable message, and data:

{
  "status": "success",
  "message": "Balance fetched",
  "data": { "balance": "1520.50", "currency": "INR" }
}

Base your logic on the status field and error codes, never on the wording of the message, which may change. Treat amounts as strings or use decimal types; floating-point numbers can introduce rounding errors in money calculations.

Common beginner mistakes

  • Not setting a timeout, so one slow call freezes a page or a worker.
  • Treating HTTP 200 as "transaction successful" without reading the body.
  • Putting the API key in front-end JavaScript or a mobile app.
  • Ignoring non-JSON responses (for example, an HTML error page from a proxy) and crashing on decode.
  • Logging full request headers, which leaks keys into log files.

Next steps

Once you are comfortable with requests and responses, the next topics are authentication, callbacks, retries and idempotency, which we cover in other posts on this blog. To start building, browse our API services, and if you would rather have our team handle the integration, see our API integration service.

0 comments

Leave a comment

Not shown publicly.
Security check image
Chat with us
Hi! Send us a message and we will reply here as soon as we can.
Security check image
Chat with us