REST API

REST API Overview

curl

# Request
curl -X GET https://stoic-api.vercel.app/api/quote \
  -H "Content-Type: application/json" \
  -d '{"id": 0}'

# Response
{
  "data": {
    "quote": "What decides whether a sum of money is good? The money is not going to tell you; it must be the faculty that makes use of such impressions – reason.",
    "author": "Epictetus",
    "source": "Discourses I, 1.5",
    "id": 0
  }
}

Fetch

// Request
await fetch('https://stoic-api.vercel.app/api/quote', {
  method: 'GET',
  headers: {
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    id: 0,
  }),
})

// Response
{
  "data": {
    "quote": "What decides whether a sum of money is good? The money is not going to tell you; it must be the faculty that makes use of such impressions – reason.",
    "author": "Epictetus",
    "source": "Discourses I, 1.5",
    "id": 0
  }
}

Possible Responses

200 OK

# Request
curl -X GET https://stoic-api.vercel.app/api/quote \
  -H "Content-Type: application/json" \
  -d '{"id": 0}'

# Response
{
  "data": {
    "quote": "What decides whether a sum of money is good? The money is not going to tell you; it must be the faculty that makes use of such impressions – reason.",
    "author": "Epictetus",
    "source": "Discourses I, 1.5",
    "id": 0
  }
}

405 Method Not Allowed

# Request
curl -X POST https://stoic-api.vercel.app/api/quote

# Response
{ "error": "Method Not Allowed", "data": null }

400 Bad Request

# Request
curl -X GET https://stoic-api.vercel.app/api/quote \
  -H "Content-Type: application/json"

# Response
{ "error": "Bad Request - `id` is required", "data": null }
# Request
curl -X GET https://stoic-api.vercel.app/api/quote \
  -H "Content-Type: application/json" \
  -d '{"id": "0"}'

# Response
{ "error": "Bad Request - `id` must be a positive number", "data": null }

429 Too Many Requests

# Request
curl -X GET https://stoic-api.vercel.app/api/quote \
  -H "Content-Type: application/json" \
  -d '{"id": 0}'

# Response
{ "error": "Too many requests, please try again later.", "data": null }
Previous
Getting started