dehaze

Querying a Service

Once you have added a remote service, you can access it via the GraphQL and REST APIs of Space Cloud.

Querying static endpointslink

Here’s how you can access a remote endpoint named adder of a service named arithmetic from your frontend:

query {
  adder(
    num1: 10,
    num2: 20
  ) @arithmetic {
    sum
  }
}
const { status, data } = await api.call("arithmetic", "adder", { num1: 10, num2: 20 })

That’s it! The arguments sent by the client (num1 and num2 in this case) are available to the remote service in the request body as well as URL params. You can pass any number of arguments to the remote endpoint.

Querying dynamic endpointslink

Let’s say you have added an endpoint hello in greeting service which accepts path parameters like these:

/hello/{args.name}

Then you can query this service in the following manner:

query {
  hello(
    name: "John"
  ) @greeting {
    sum
  }
}
const { status, data } = await api.call("greeting", "hello", { name: "John" })

The remote service gets name: John in the URL parameters as well as in the request body.

Have a technical question?

Improve the docs!