Tony Spiro
February 14, 2017
We are excited to announce the addition of our GraphQL API to help you build content-powered apps faster and more efficiently. The Cosmic community has been very supportive of adding GraphQL as an alternative to our REST API and we are happy to now make this available. Check out the new documentation to learn more about GraphQL methods to get your content.
What is GraphQL?
If you don’t know about GraphQL, it has been gaining popularity since Facebook open-sourced the project a couple of years ago. It is an API alternative to the traditional REST-ful approach to fetching data from an endpoint.
Why is GraphQL so Special?
GraphQL gives you the power to be more efficient with your API calls by allowing clients to query only specific values, limiting the amount of data returned. From the official website: it “gives clients the power to ask for exactly what they need and nothing more”. For instance here is a response from our (still awesome) REST API:
https://api.cosmicjs.com/v1/creative-agency/object/about?hide_metafields=true&pretty=true
And here is the same response specifying which fields to return using GraphQL (if you just need to get title and content):
So you can see the difference in returned data. This is more declarative and more empowering for every client accessing the API. The new Cosmic GraphQL API gives you the ability to access just what you need from your Buckets and nothing
you don’t. This is especially great for mobile when every saved network byte counts.
We hope you enjoy the addition of GraphQL to help you build apps faster, now with less unused data. Learn more about the Cosmic GraphQL API in the documentation. Let us know if you have any questions by joining the community on Slack or reaching out on Twitter.