Fetch topics
Single topic
You can fetch the value of a single topic with the REST API.
curl --include \
--request POST \
--url https://api.diffusion.cloud/topics/fetch \
--header 'authorization: Apikey <TOKEN>' \
--header 'content-type: application/json' \
-d '{"path":"my-fetched-topic", "type":"json"}'
Multiple topics
You can fetch the values of multiple topics using a topic selector.
For example, this will fetch the values of my-fetched-topic and any descendant topics (such as my-fetched-topic/a or my-fetched-topic/a/b) as an array:
curl --include \
--request POST \
--url https://api.diffusion.cloud/topics/fetch \
--header 'authorization: Apikey <TOKEN>' \
--header 'content-type: application/json' \
-d '{"selector":"*my-fetched-topic//", "type":"json"}'
If you have lots of topics, this could return a large number of results; hence, responses are paged. The default size is 10 results per page.
For example, if the topic selector above, matches 100 topics, the response only includes values for the first 10. This is the beginning of the response body:
{
"has_more":true,
"results":
[
{"path":"my-fetched-topic","type":"json","value":{"foo":"bar"}},
{"path":"my-fetched-topic/a","type":"json","value":{"foo":"bar"}},
...
]
}
The has_more value of true tells you that there are more values.
You can request the next set of values using the after parameter.
For example, the last value you had received was for the topic my-fetched-topic/a/b/c/d/e.
You could send this request to get the next 10 values:
curl --include \
--request POST \
--url https://api.diffusion.cloud/topics/fetch \
--header 'authorization: Apikey <TOKEN>' \
--header 'content-type: application/json' \
-d '{"selector":"*my-fetched-topic//", "type":"json", "after":"my-fetched-topic/a/b/c/d/e"}'
and repeat until the final page is indicated by has_more":false. after is non-inclusive - the topic it names is not repeated in the next page.
You can set a custom page size using the size parameter.
Endpoint |
|
Content-type |
|
Method |
|
Required scope(s) |
|
| Parameter | Optional? | Default | Description |
|---|---|---|---|
path |
Yes |
— |
The Diffusion topic path as a string. It is mandatory to provide either the path or the selector, but not both. |
selector |
Yes |
— |
The Diffusion topic selector as a string. It is mandatory to provide either the path or the selector, but not both. |
type |
Yes |
json |
The topic type. Either |
size |
Yes |
10 |
The number of results to return. This is used for paging results. |
after |
Yes |
Returns results from the beginning |
Specifies the start point in the topic tree, non-inclusive. This is used for paging results. |
| Code | Description |
|---|---|
|
The topic or topics were fetched successfully. If |
|
There was a problem fetching values due to the parameters supplied. See |
|
There was an unexpected problem fetching the values. See |
Further reading
This endpoint is a thin wrapper around the JavaScript client SDK’s fetch feature - see Topics.fetchRequest (the factory method that starts a fetch) and FetchRequest.fetch (the builder method that runs it) in the JavaScript SDK reference for more detail on the full range of fetch options available at the client level, beyond what this REST endpoint exposes.