Categories
Ce contenu n’est pas encore disponible dans votre langue.
Overview
Section titled “Overview”The Categories resource provides fake product category data with names, slugs, descriptions, and images.
Endpoints
Section titled “Endpoints”| Method | Endpoint | Description |
|---|---|---|
| GET | /v1/categories | List all categories |
| GET | /v1/categories/:id | Get a specific category |
| GET | /v1/categories/:id/products | Get category's products |
Category Object
Section titled “Category Object”{ "id": 1, "name": "Electronics", "slug": "electronics", "description": "Electronic devices and gadgets", "image": "https://example.com/images/electronics.jpg"}| Field | Type | Description |
|---|---|---|
id |
number |
Unique identifier |
name |
string |
Category name |
slug |
string |
URL-friendly unique slug |
description |
string |
Category description |
image |
string |
Category image URL |
List Categories
Section titled “List Categories”curl https://api.phantomjson.app/v1/categoriesQuery Parameters
Section titled “Query Parameters”| Parameter | Type | Default | Description |
|---|---|---|---|
page |
number |
1 |
Page number |
limit |
number |
20 |
Items per page (max: 100) |
sort |
string |
— | Sort field and direction |
q |
string |
— | Search query |
fields |
string |
— | Fields to return |
name |
string |
— | Filter by name |
Response
Section titled “Response”{ "data": [ { "id": 1, "name": "Electronics", "slug": "electronics", "description": "Electronic devices and gadgets" } ], "meta": { "total": 20, "page": 1, "limit": 20, "totalPages": 1 }}Get Category by ID
Section titled “Get Category by ID”curl https://api.phantomjson.app/v1/categories/1Response
Section titled “Response”{ "data": { "id": 1, "name": "Electronics", "slug": "electronics", "description": "Electronic devices and gadgets", "image": "https://example.com/images/electronics.jpg" }}Get Category’s Products
Section titled “Get Category’s Products”curl https://api.phantomjson.app/v1/categories/1/productsResponse
Section titled “Response”{ "data": [ { "id": 1, "name": "Ergonomic Rubber Keyboard", "slug": "ergonomic-rubber-keyboard", "price": 299.99, "categoryId": 1 } ], "meta": { "total": 50, "page": 1, "limit": 20, "totalPages": 3 }}Examples
Section titled “Examples”Search Categories
Section titled “Search Categories”curl "https://api.phantomjson.app/v1/categories?q=electronics"Sort by Name
Section titled “Sort by Name”curl "https://api.phantomjson.app/v1/categories?sort=name:asc"Field Selection
Section titled “Field Selection”curl "https://api.phantomjson.app/v1/categories?fields=id,name,slug"Relations
Section titled “Relations”- Products — Each category has many products (access via
/v1/categories/:id/products)
