API Workflow - Authentication and Order
Real-world APIs require multi-step workflows, where one response feeds the next request. This assignment chains:
- Login: POST to
/auth/login → read the logged-in user and the JWT token
- Create Order: POST to
/orders with userId and productId, sending the token in an Authorization: Bearer <token> header → get the order confirmation
The order response includes expanded user and product data, for example user.name and product.name.
On this practice API, /orders does not check the token, so an order without it still succeeds here. Real order APIs answer 401 without one, so send it the way a real client would.
Task:
- Log in as
admin / secret123 and print the user field after the label Logged in as: (never print the token itself; it changes every second)
- Create the order from the starter code with the Bearer header, and validate status 201
- Print the order ID, user name, product name, total and status as shown below
Expected output:
Logged in as: admin
Order ID: ORD-001
User: John Doe
Product: Wireless Mouse
Total: 29.99
Status: confirmed