Simple API design for WebGroup.
Store has categories and products beloned to. Each product may has several tags.
All api calls returns data as JSON or XML. You must set Accept
header to determine response format, eg Accept: application/json
.
If unsupported format given, server returns 406 Not acceptable
.
Authentication is not needed.
API calls represnted as VERB /api/path
, where VERB
- HTTP verb and /api/path
- API path.
If given parameter is wrong server returns 400 Bad request
:
{"error": "Unknown parameter given: foo"}
If parameter given is correct but given wrong value server returns 422 Unprocessable entity
:
{"error": "The tags parameters accepts the array of strings"}
GET /api/v1/categories
Returns an Array of categories
[
{"id": 1, "name": "Desktops"},
{"id": 2, "name": "Laptops"},
{"id": 3, "name": "Printers, scanners and MFD"},
{"id": 4, "name": "Mobile phones"}
]
GET /api/v1/categories/:category_id
:category_id
- the ID of given category, eg:1
Returns details of category as a Object with 200 OK
if exists or 404 Not Found
header otherwise, eg:
{"error": "Category not found"}
HEAD /api/v1/categories/:category_id
Returns header 200 OK
if exists or 404 Not Found
header otherwise.
List of products belonged to category with ID :category_id
GET /api/v1/categories/:category_id/products
:category_id
- the ID of given category, eg:1
Returns an Array of products.
[
{
"id": 1,
"category_id": 2,
"name": "Apple MacBook Pro 13\" with Retina display 2014 (MGX72)",
"price": 1500.0,
"currency": "USD",
"tags": ["apple", "macbook", "macbook pro", "laptop", "os x"]
},
{
"id": 2,
"category_id": 2,
"name": "Apple MacBook Air 13\" (MD760) (2014)",
"price": 1100.0,
"currency": "USD",
"tags": ["apple", "macbook", "macbook air", "laptop", "os x"]
},
{
"id": 3,
"category_id": 2,
"name": "ASUS Transformer Book T100TA (T100TA-DK003H)",
"price": 400.0,
"currency": "USD",
"tags": ["asus", "transformer book", "laptop", "windows"]
},
{
"id": 4,
"category_id": 4,
"name": "Apple iPhone 6 64GB (Space Gray)",
"price": 850.0,
"currency": "USD",
"tags": ["apple", "iphone", "iphone 6", "smartphone", "space gray", "ios"]
},
{
"id": 5,
"category_id": 4,
"name": "HTC One 801e (Silver)",
"price": 440.0,
"currency": "USD",
"tags": ["htc", "htc one", "silver", "smartphone", "android"]
}
]
Returns an Array of products.
GET /api/v1/categories/:category_id/products
:category_id
- the ID of given category, eg:1
tags[]
- list of tags, eg:tags[]=apple&tags[]=macbook
operator
(optional) - logical operator, may beAND
(default),OR
.
GET /api/v1/categories/:category_id/products?tags[]=apple&tags[]=laptop&operator=AND
[
{
"id": 1,
"category_id": 2,
"name": "Apple MacBook Pro 13\" with Retina display 2014 (MGX72)",
"price": 1500.0,
"currency": "USD",
"tags": ["apple", "macbook", "macbook pro", "laptop", "os x"]
},
{
"id": 2,
"category_id": 2,
"name": "Apple MacBook Air 13\" (MD760) (2014)",
"price": 1100.0,
"currency": "USD",
"tags": ["apple", "macbook", "macbook air", "laptop", "os x"]
}
]
GET /api/v1/categories/:category_id/products/:product_id
:category_id
- the ID of given category, eg:1
:product_id
- the ID of given product, eg:1
Returns details of category as a Object with 200 OK
if exists or 404 Not Found
header otherwise, eg:
{"error": "Product not found"}
GET /api/v1/categories/4/products/4
{
"id": 4,
"category_id": 4,
"name": "Apple iPhone 6 64GB (Space Gray)",
"price": 850.0,
"currency": "USD",
"tags": ["apple", "iphone", "iphone 6", "smartphone", "space gray", "ios"]
}