Advanced API Patterns
Batch Transactions
Insert multiple entities at once:
curl -X POST http://localhost:58090/fluree/transact \ -H "Content-Type: application/json" \ -d '{ "ledger": "my/ledger", "insert": [ { "id": "ex:users/1", "type": "ex:User", "schema:name": "Alice" }, { "id": "ex:users/2", "type": "ex:User", "schema:name": "Bob" }, { "id": "ex:users/3", "type": "ex:User", "schema:name": "Carol" } ] }'
Error Handling
Check the response status:
200: Success400: Invalid request (check query syntax)500: Server error
Response includes details:
{ "error": "Invalid query syntax", "message": "..."}
Pagination
Use limit and offset:
curl -X POST http://localhost:58090/fluree/query \ -H "Content-Type: application/json" \ -d '{ "ledger": "my/ledger", "select": { "?user": ["*"] }, "where": { "@id": "?user", "@type": "ex:User" }, "limit": 10, "offset": 20 }'
History Query
curl -X POST http://localhost:58090/fluree/history \ -H "Content-Type: application/json" \ -d '{ "ledger": "my/ledger", "history": { "@id": "ex:users/1" } }'
Query with Context
Include context in the request:
curl -X POST http://localhost:58090/fluree/query \ -H "Content-Type: application/json" \ -d '{ "ledger": "my/ledger", "@context": { "ex": "https://example.com/ns/", "schema": "http://schema.org/" }, "select": { "?user": ["schema:name"] }, "where": { "@id": "?user", "@type": "ex:User" } }'