api.macomb.io

Macomb.io REST API — help guide for student assignments. All endpoints return JSON.

⚠ HTTP Only Because of the complexity of handling HTTPS in client applications, this API is currently only available over HTTP. Always use http://api.macomb.io in your code and API testing tools. Do not attempt to use https://api.macomb.io as it will not work and may cause confusion.
⚠ Before you start Any changes made via POST requests are saved in memory only and will be lost when the server restarts.
Please do not submit sensitive information or inappropriate content.

Jokes

The jokes endpoint lets you fetch random jokes and add your own to the server.

GET Fetch random jokes — optional query params to filter
POST Add a new joke — send a JSON body

Getting jokes

Send a GET request to fetch one or more random jokes. Without any parameters you get one joke chosen at random from all categories.

Request

Response

{
  "count": 1,
  "jokes": [
    {
      "id": 7,
      "category": "programming",
      "setup": "Why did the developer go broke?",
      "punchline": "Because they used up all their cache."
    }
  ]
}

Fields to parse

FieldTypeDescription
countnumberHow many jokes were returned
jokesarrayThe list of jokes
jokes[i].idnumberUnique ID of the joke
jokes[i].categorystringCategory the joke belongs to
jokes[i].setupstringThe setup line of the joke
jokes[i].punchlinestringThe punchline

Query parameters — both optional and combinable

ParameterTypeDefaultDescription
countnumber1How many jokes to return. Min 1, max 10.
categorystringallFilter by category.

Available categories: programming, general, math

Example requests

http://api.macomb.io/jokes
http://api.macomb.io/jokes?count=3
http://api.macomb.io/jokes?category=programming
http://api.macomb.io/jokes?count=5&category=math

If you request more jokes than exist in a category, the server returns however many it has — it won't error out.

Adding a joke (POST)

Send a POST request with a JSON body to add your own joke. Once added, it can be returned by future GET requests.

Request body

{
  "category": "programming",
  "setup": "Why did the programmer quit his job?",
  "punchline": "Because he didn't get arrays."
}

Required fields

FieldTypeValid values
categorystringprogramming, general, math
setupstringAny non-empty string
punchlinestringAny non-empty string

Response — success (HTTP 201)

{
  "message": "joke added successfully",
  "joke": {
    "id": 16,
    "category": "programming",
    "setup": "Why did the programmer quit his job?",
    "punchline": "Because he didn't get arrays."
  }
}

The server assigns the id automatically. Check the response to see what ID your joke was given.

Error responses

All errors use the same shape:

{ "error": "description of what went wrong" }
HTTP StatusReason
400Missing category, setup, or punchline
400Invalid category value
400Invalid JSON body
405Wrong HTTP method

Testing without writing code

Open these in your browser (GET only):

http://api.macomb.io/jokes
http://api.macomb.io/jokes?count=3
http://api.macomb.io/jokes?category=programming

Using curl (Git Bash, WSL, or PowerShell):

curl http://api.macomb.io/jokes
curl "http://api.macomb.io/jokes?count=3"
curl "http://api.macomb.io/jokes?category=programming"
curl -X POST http://api.macomb.io/jokes \
     -H "Content-Type: application/json" \
     -d "{\"category\":\"general\",\"setup\":\"Why did the bike fall over?\",\"punchline\":\"Because it was two tired.\"}"

Things to watch out for

  • jokes is always an array — even when count is 1, you still need to index into [0]. Never assume the response is a single object.
  • JSON strings include quote marks — string values are wrapped in " characters you need to strip before displaying or storing them.
  • Jokes are random — the server shuffles before picking, so you will get different jokes each time. Don't write code that assumes a specific joke will come back.
  • In-memory only — jokes added via POST disappear if the server restarts. This is expected.

Trivia

The trivia endpoint lets you fetch random multiple choice questions and add your own questions to the server.

GET Fetch random questions — optional query params to filter
POST Add a new question — send a JSON body

Getting questions

Send a GET request to fetch one or more random trivia questions. Without any parameters you get one question chosen at random from all categories and difficulty levels.

Request

Response

{
  "count": 1,
  "questions": [
    {
      "id": 4,
      "category": "programming",
      "difficulty": "medium",
      "question": "What is the output of: int x = 5; cout << x++;",
      "answer": "5",
      "choices": [ "6", "Undefined", "5", "4" ]
    }
  ]
}

Fields to parse

FieldTypeDescription
countnumberHow many questions were returned
questionsarrayThe list of questions
questions[i].idnumberUnique ID of the question
questions[i].categorystringCategory the question belongs to
questions[i].difficultystringeasy, medium, or hard
questions[i].questionstringThe trivia question text
questions[i].answerstringThe correct answer
questions[i].choicesarray of stringsFour possible answers (order is random)

Query parameters — all optional and combinable

ParameterTypeDefaultDescription
countnumber1How many questions to return. Min 1, max 10.
categorystringallFilter by category.
difficultystringallFilter by difficulty level.

Available categories: programming, math, science, history
Available difficulties: easy, medium, hard

Example requests

http://api.macomb.io/trivia
http://api.macomb.io/trivia?count=5
http://api.macomb.io/trivia?category=programming
http://api.macomb.io/trivia?difficulty=easy
http://api.macomb.io/trivia?category=science&difficulty=hard
http://api.macomb.io/trivia?category=history&count=3
http://api.macomb.io/trivia?category=math&difficulty=medium&count=2

Adding a question (POST)

Request body

{
  "category": "science",
  "difficulty": "easy",
  "question": "What is the powerhouse of the cell?",
  "answer": "Mitochondria",
  "choices": [ "Mitochondria", "Nucleus", "Ribosome", "Golgi apparatus" ]
}

Required fields

FieldTypeRules
categorystringMust be programming, math, science, or history
difficultystringMust be easy, medium, or hard
questionstringAny non-empty string
answerstringMust exactly match one of the entries in choices
choicesarray of stringsMust contain exactly 4 options

Response — success (HTTP 201)

{
  "message": "question added successfully",
  "question": {
    "id": 30,
    "category": "science",
    "difficulty": "easy",
    "question": "What is the powerhouse of the cell?",
    "answer": "Mitochondria",
    "choices": [ "Mitochondria", "Nucleus", "Ribosome", "Golgi apparatus" ]
  }
}

Error responses

{ "error": "description of what went wrong" }
HTTP StatusReason
400Missing required fields
400Invalid category or difficulty value
400choices does not contain exactly 4 options
400answer does not match any entry in choices
400Invalid JSON body
405Wrong HTTP method

Testing without writing code

curl http://api.macomb.io/trivia
curl "http://api.macomb.io/trivia?count=5"
curl "http://api.macomb.io/trivia?category=programming&difficulty=easy"
curl -X POST http://api.macomb.io/trivia \
     -H "Content-Type: application/json" \
     -d "{\"category\":\"science\",\"difficulty\":\"easy\",\"question\":\"What is the powerhouse of the cell?\",\"answer\":\"Mitochondria\",\"choices\":[\"Mitochondria\",\"Nucleus\",\"Ribosome\",\"Golgi apparatus\"]}"

Things to watch out for

  • questions is always an array — even when count is 1, you still need to index into [0].
  • choices is also an array — you need to loop through it separately after parsing the question object.
  • choices order is random every time — never assume the correct answer is at a fixed position. Always use the answer field.
  • answer must match choices exactly on POST — capitalization and spacing must match precisely.
  • JSON strings include quote marks — strip " characters before displaying or storing values.
  • In-memory only — questions added via POST disappear if the server restarts. This is expected.

Currency

The currency endpoint lets you look up supported currencies, convert between any two of them, and add your own currency rates to the server.

GET No params: list all currencies  |  With from + to: convert an amount
POST Add or update a currency rate — send a JSON body

Listing all currencies

Send a plain GET request with no query parameters and you get back every currency the server knows about.

Response

{
  "count": 20,
  "currencies": [
    { "code": "USD", "name": "US Dollar", "symbol": "$",  "rate_usd": 1.0  },
    { "code": "EUR", "name": "Euro",       "symbol": "€",  "rate_usd": 0.92 }
  ]
}

The rate_usd field tells you how many units of that currency equal one US Dollar. For example, "rate_usd": 0.92 means 1 USD = 0.92 EUR.

Fields to parse

FieldTypeDescription
countnumberTotal number of currencies returned
currenciesarrayList of currency objects
currencies[i].codestring3-letter currency code (e.g. USD, EUR)
currencies[i].namestringFull name of the currency
currencies[i].symbolstringCurrency symbol (e.g. $, , £)
currencies[i].rate_usdnumberUnits of this currency per 1 USD

Supported currencies (20 total)

CodeCurrencyCodeCurrency
USDUS DollarKRWSouth Korean Won
EUREuroSEKSwedish Krona
GBPBritish PoundNOKNorwegian Krone
JPYJapanese YenDKKDanish Krone
CADCanadian DollarNZDNew Zealand Dollar
AUDAustralian DollarSGDSingapore Dollar
CHFSwiss FrancHKDHong Kong Dollar
CNYChinese YuanZARSouth African Rand
INRIndian RupeeAEDUAE Dirham
MXNMexican PesoBRLBrazilian Real
Note: These are approximate fixed rates loaded at server startup — not live market data. Think of them as reasonable estimates for learning purposes.

Converting between currencies

Add from and to query parameters to perform a conversion. amount is optional and defaults to 1. Currency codes are case-insensitive.

Example requests

http://api.macomb.io/currency?from=USD&to=EUR&amount=100
http://api.macomb.io/currency?from=GBP&to=JPY&amount=50
http://api.macomb.io/currency?from=CAD&to=MXN&amount=200
http://api.macomb.io/currency?from=EUR&to=INR

Response

{
  "conversion": {
    "from": "USD",
    "to": "EUR",
    "amount": 100.0,
    "result": 92.0,
    "rate": 0.92,
    "from_symbol": "$",
    "to_symbol": "€"
  }
}

Fields to parse

FieldTypeDescription
conversion.fromstringSource currency code
conversion.tostringTarget currency code
conversion.amountnumberThe amount you sent in
conversion.resultnumberThe converted amount (4 decimal places)
conversion.ratenumberHow many to units equal 1 from unit
conversion.from_symbolstringSymbol for the source currency
conversion.to_symbolstringSymbol for the target currency

How the math works

The server converts everything through USD as a middle step:

amount ÷ from_rate  =  USD equivalent
USD equivalent × to_rate  =  final result

So converting 100 GBP to JPY would be:

100 ÷ 0.79 = 126.58 USD
126.58 × 149.50 = 18,923.71 JPY

You can verify your program got it right by doing this math yourself.

Adding a currency (POST)

You can add a new currency or update the rate of an existing one by sending a POST request with a JSON body.

Request body

{
  "code": "PLN",
  "name": "Polish Zloty",
  "symbol": "zł",
  "rate_usd": 3.94
}

Required fields

FieldTypeDescription
codestring3-letter currency code (automatically uppercased)
namestringFull name of the currency
symbolstringCurrency symbol
rate_usdnumberHow many units of this currency equal 1 USD (must be positive)

Response — new currency added (HTTP 201)

{
  "message": "currency added successfully",
  "currency": { "code": "PLN", "name": "Polish Zloty", "symbol": "zł", "rate_usd": 3.94 }
}

Response — existing currency updated (HTTP 201)

{
  "message": "currency rate updated successfully",
  "currency": { "code": "EUR", "name": "Euro", "symbol": "€", "rate_usd": 0.94 }
}

Notice the message field tells you whether a new currency was added or an existing one was updated. Your program should read this field — don't assume one or the other.

Error responses

{ "error": "description of what went wrong" }
HTTP StatusReason
400Missing required fields
400rate_usd is zero or negative
400Invalid JSON body
405Wrong HTTP method

Testing without writing code

curl http://api.macomb.io/currency
curl "http://api.macomb.io/currency?from=USD&to=EUR&amount=100"
curl "http://api.macomb.io/currency?from=GBP&to=JPY&amount=50"
curl -X POST http://api.macomb.io/currency \
     -H "Content-Type: application/json" \
     -d "{\"code\":\"PLN\",\"name\":\"Polish Zloty\",\"symbol\":\"zł\",\"rate_usd\":3.94}"
curl "http://api.macomb.io/currency?from=USD&to=PLN&amount=10"

Things to watch out for

  • Two different JSON shapes from the same URL — a GET with no params returns a currencies array; a GET with from/to returns a conversion object. Use separate functions for each.
  • amount defaults to 1 — if you omit it, the result field will just be the exchange rate itself.
  • Rates are not live — the server uses fixed approximate rates. Do not use this for anything financial.
  • In-memory only — currencies added via POST disappear if the server restarts. This is expected.
  • result is rounded to 4 decimal places, rate to 6 — consider rounding your display output.