🌍

states

State or province administrative division with name, code, country, population, and capital city. Used for geographic databases, address systems, and administrative data.

🎯 Request Builder

https://api.mockly.codes/states?page=1&limit=10&count=10
📡

Configure your request and click Send Request to see the response here.

Endpoints

GET/states

Get a collection of states

Alternative: /location/states
GET/states/:id

Get a single state by ID

Alternative: /location/states/:id
GET/states/meta

Get resource metadata and schema

Alternative: /location/states/meta
🔍

How to Use Search

The search feature allows you to filter results by searching for text across all or specific fields. Choose between ?q= or ?search= parameter names.

1. Basic Search

Search across all text fields:

Basic Search
GET https://api.mockly.codes/states?q=laptop

2. Search Specific Fields

Field-Specific Search
GET https://api.mockly.codes/states?q=laptop&search_fields=name,description

💡 Pro Tips

  • Search is case-insensitive and performs partial matching
  • Without search_fields, all text fields are searched
  • Combine with pagination to handle large result sets efficiently

Code Examples

JavaScript

Fetch Collection
// Get 10 states
fetch('https://api.mockly.codes/states?count=10')
  .then(res => res.json())
  .then(data => console.log(data));

Python

Fetch with Requests
import requests

response = requests.get(
    'https://api.mockly.codes/states?count=10'
)
data = response.json()

cURL

Command Line
curl "https://api.mockly.codes/states?count=10"

Bypass Cache

Get Fresh Data
fetch('https://api.mockly.codes/states?nocache=true')

Schema Properties

idinteger

Unique identifier for the state record

Gen:random_int
namestring

Official name of the state or province (e.g., California, Ontario, Bavaria)

Gen:state
codestring

State or province code or abbreviation (e.g., CA, ON, BY)

Gen:word
countrystring

Country where this state or province is located

Gen:country
populationinteger

Total population of the state or province

Gen:random_int
capitalstring

Capital city of the state or province

Gen:city

Query Parameters

countinteger

Number of items to return (default: 10, max: 100)

seedinteger

Seed for reproducible data generation

nocacheboolean

Bypass cache and generate fresh data on every request