Code example

Pincode API in Ruby

A practical Ruby example for retrieving Indian postal information by PIN code.

Ruby with Net::HTTP

require "net/http"
require "json"

uri = URI("https://api.pincodeapi.in/api/v1/pincode/751001")
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.open_timeout = 5
http.read_timeout = 10
response = http.get(uri.request_uri)
raise "HTTP #{response.code}" unless response.is_a?(Net::HTTPSuccess)
result = JSON.parse(response.body)
raise "API request failed" unless result["success"]
puts result["data"]["post_offices"].map { |o| o["office_name"] }

V1 response contract

Successful responses use success, endpoint-specific data and a meta object. Postal records use snake_case fields such as office_name, office_type, delivery_status, district and state.

Handling 404 and 429 responses

The current public limit is 6 API calls per 10 seconds per IP address. A 404 means the requested record was not found and should not be retried unchanged. A 429 means the rate limit was reached; respect Retry-After when the API supplies it. Limit retries and add jitter so many clients do not retry at exactly the same moment.

See the complete API documentation, response guide and Abuse Policy.