Query Parameters
Query params work on GET (filter response), PATCH (select items to update), and DELETE (select items to remove).
Search
?search=<term>Case-insensitive match against all string fields.
GET
/johndoe/products?search=gad
const res = await fetch("https://json.shahriyar.dev/johndoe/products?search=gad")
const data = await res.json()
console.log(data)Sort (GET only)
?sort=<field>&order=asc|descDefault order asc.
GET
/johndoe/products?sort=price
const res = await fetch("https://json.shahriyar.dev/johndoe/products?sort=price")
const data = await res.json()
console.log(data)GET
/johndoe/products?sort=price&order=desc
const res = await fetch("https://json.shahriyar.dev/johndoe/products?sort=price&order=desc")
const data = await res.json()
console.log(data)Filter
Two syntaxes:
Colon
?filter=<key>:<value>GET
/johndoe/products?filter=inStock:true
const res = await fetch("https://json.shahriyar.dev/johndoe/products?filter=inStock:true")
const data = await res.json()
console.log(data)Direct
?<key>=<value>GET
/johndoe/products?inStock=true
const res = await fetch("https://json.shahriyar.dev/johndoe/products?inStock=true")
const data = await res.json()
console.log(data)Pagination (GET only)
?_limit=5
?_skip=10
?_start=0&_end=5Mutations
Query params select items for batch update or delete.
PATCH
/johndoe/products?inStock=false
const res = await fetch("https://json.shahriyar.dev/johndoe/products?inStock=false", {
method: "PATCH",
headers: { Authorization: "Bearer js_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" },
body: JSON.stringify({...}),
})
const data = await res.json()
console.log(data)DELETE
/johndoe/products?inStock=false
const res = await fetch("https://json.shahriyar.dev/johndoe/products?inStock=false", {
method: "DELETE",
headers: { Authorization: "Bearer js_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" },
})
const data = await res.json()
console.log(data)Combined
GET
/johndoe/products?search=pro&sort=price&order=desc&_limit=10
const res = await fetch("https://json.shahriyar.dev/johndoe/products?search=pro&sort=price&order=desc&_limit=10")
const data = await res.json()
console.log(data)PATCH
/johndoe/store/inventory/items?category=electronics
const res = await fetch("https://json.shahriyar.dev/johndoe/store/inventory/items?category=electronics", {
method: "PATCH",
headers: { Authorization: "Bearer js_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" },
body: JSON.stringify({...}),
})
const data = await res.json()
console.log(data)DELETE
/johndoe/store/inventory/items?inStock=false
const res = await fetch("https://json.shahriyar.dev/johndoe/store/inventory/items?inStock=false", {
method: "DELETE",
headers: { Authorization: "Bearer js_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" },
})
const data = await res.json()
console.log(data)