API keys (E-commerce Store (full stack))

Customers authenticate with API keys. KEY <key <user [admin] lines register keys; a request may start with key=<key. /products stays public. Everything else needs a valid key: none → 401 {"error":"missing api key"}, unknown → 401 {"error":"invalid api key"}. /admin/… also needs an admin key → 403 {"error":"admin only"}. GET /me → 200 {"admin":false,"user":"ann"}.

Input: As before, plus keys.

Output: As before.

Difficulty: Medium. Write your answer in the browser editor, run the examples, then submit it against hidden tests. Python and JavaScript are free; other languages are part of licode Club.

Hint

  • Strip key= from the front of the line before parsing the request.

More E-commerce Store (full stack) practice