Examples

These snippets match the Pionia Shop tutorial. Copy them as starting points for the store API on port 8000.

Pick your learning path

Try the tutorial

Build the services behind these curls.

Moonlight overview

How service and action map to HTTP.

What these examples cover

ExampleActionLearn more
PingHealth checkIntroduction
List productsproduct.listTutorial
Create productproduct.createValidation
Customer logincustomer.loginJWT
Place orderorder.placeProtecting actions

Ping

curl -s http://127.0.0.1:8000/api/v1/ping

List products

curl -s -X POST http://127.0.0.1:8000/api/v1/ \
  -H "Content-Type: application/json" \
  -d '{"service":"product","action":"list"}'
Result
{
  "returnCode": 0,
  "returnMessage": "OK",
  "returnData": {
    "products": [
      { "id": 1, "name": "Ada Mug", "price": 24.5, "stock": 12 }
    ]
  }
}

Create product (authenticated)

curl -s -X POST http://127.0.0.1:8000/api/v1/ \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -d '{"service":"product","action":"create","name":"Tote Bag","price":18,"stock":40}'

Customer login

curl -s -X POST http://127.0.0.1:8000/api/v1/ \
  -H "Content-Type: application/json" \
  -d '{"service":"customer","action":"login","email":"ada@pionia.shop","password":"secret"}'
Result
{
  "returnCode": 0,
  "returnMessage": "Logged in",
  "returnData": { "token": "eyJhbGciOiJIUzI1NiJ9..." }
}

Place order (authenticated)

curl -s -X POST http://127.0.0.1:8000/api/v1/ \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -d '{"service":"order","action":"place","product_id":1,"quantity":2}'

Wallet balance

curl -s -X POST http://127.0.0.1:8000/api/v1/ \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -d '{"service":"wallet","action":"balance"}'