GraphQL vs REST
7 min
graphql vs rest litmus uses both knowing which module is which prevents the most common 200 with no data confusion which modules use which module protocol le devicehub graphql at /devicehub/v2 (most ops); a few rest endpoints for csv upload/download and storage toggle le digital twins graphql at /digitaltwins/v2 le integration graphql at /cc/v2 le opc ua graphql at /opcua/v2 le datahub, flows, analytics, applications, system, auth rest lem (all modules) rest luns (all modules) graphql at /mqtt/gql graphql gotchas 1\ error envelope graphql endpoints return http 200 even on validation errors the error sits in the body { "data" null, "errors" \[ { "message" "driver not found", "path" \["createdevice"] } ] } your client must check body errors , not just the http status treat errors being a non empty array as a failure 2\ operation name is in the body rest callers think in urls graphql callers think in operations the url stays the same; the query or mutation selects the action \# same url, two different operations curl x post /devicehub/v2 d '{"query" "query { listdrivergroups { } }"}' curl x post /devicehub/v2 d '{"query" "mutation { createdevice(input { }) { id } }"}' 3\ field selection is required you must explicitly name the fields you want back asking for everything in a single query is not idiomatic request only what you'll read 4\ pagination, filtering, sorting these vary per operation most list operations accept an input argument with limit , offset , filter , sort fields check the operation's schema before assuming defaults rest conventions in litmus path versioned /devicehub/v2 , /digitaltwins/v2 , /dm/template/v2 new major versions don't break old clients resumable uploads delete > post {size} > put {bytes} pattern see resumable uploads # async tasks (lem) post returns taskid , then get /async task/{id}/subtasks polls until success standard http status codes 200/201 success, 400 validation, 401 auth, 403 forbidden, 404 missing, 5xx server how to spot graphql vs rest on the api portal browsing api litmus io graphql requests show as post with a json body containing query and optional variables rest requests show varied http methods and typed bodies look at the url anything ending in /v2 with no further path ( /devicehub/v2 , /cc/v2 , /opcua/v2 , /digitaltwins/v2 , /mqtt/gql ) is graphql