With Khoros Communities Aurora, we are transitioning to a GraphQL framework for APIs. While REST APIs are still supported in Khoros Communities Classic, we strongly recommend adopting GraphQL for all new components, endpoints, and integrations in Aurora.
Our long-term strategy is to phase out REST APIs in favor of GraphQL. Although we have not announced a sunset date yet, GraphQL is where we are focusing all new development and enhancements. We encourage all customers upgrading to Aurora to begin transitioning as early as possible. Early adoption will help ensure a smoother and more efficient migration experience in the future.
Example
Here’s an example comparing a REST API call and a GraphQL mutation for the same action: creating a community-level role titled “AwesomeBlossom.”
REST API v1 Method
Using Khoros Communities' original REST API v1 you can create a new role through an authenticated request.
REST API v1:
https://community.khoros.com/restapi/vc/roles/create?role.name=AwesomeBlossom
Curl Example:
curl -L -X POST '{community-domain}/restapi/vc/roles/create?role.name=AwesomeBlossom' \
-H 'li-api-session-key: [SESSION KEY]'
GraphQL Method
The GraphQL method requires a single request as well; however, you have the option to add additional queries and requests to the call since every operation is handled through the API's single endpoint. Additionally, you can specify which information you want to receive as a response to the request so you get exactly what you need and nothing you don't.
GraphQL query:
mutation createAwesomeBlossomRole($key: RoleKeyInput!, $description: String) {
createRole(
input: {
key: $key,
name: "AwesomeBlossom",
description: $description
}
) {
id
name
description
}
}
GraphQL variables:
{
"key": {
"id": "AwesomeBlossom"
},
"description": "This is the AwesomeBlossom role."
}
Advantages of Using GraphQL Over REST API
- Request Only the Data You Need: GraphQL enables you to specify exactly which fields you want, minimizing over-fetching and optimizing performance.
- Single Endpoint: Interact with the entire API through a single endpoint, simplifying development and reducing the need for multiple network calls.
- Strong Typing: GraphQL’s robust type system helps detect errors early and provides built-in, self-documenting schema support.
- Real-Time Capabilities: GraphQL supports subscriptions, making it easier to build real-time features and push notifications compared to REST APIs.
- Efficient Data Retrieval: Fetch related resources in a single request, improving network efficiency and reducing latency.
- Improved Developer Experience: GraphQL offers a modern, intuitive developer experience with tools like GraphiQL for exploring and testing queries interactively.
We strongly encourage you to begin your transition to GraphQL as part of your Aurora upgrade to take full advantage of these benefits and to future-proof your integrations.
Next Steps
- Review the GraphQL documentation and examples provided.
- Begin testing GraphQL queries in your development environment.
- Work with your development team to plan a migration strategy for updating existing REST API integrations and customizations.
ATLAS
Comments