Here's a quick summary of everything we released in Q1 2024.

Headless CMS for Ruby

Hygraph is the ideal Headless CMS for Ruby websites and applications. Read further to learn how our API-first CMS allows you to add components to your Ruby apps in minutes and enable your website's content to be managed from a powerful CMS.

Step #1 - Construct your query and fetch the data from Hygraph

To query a GraphQL API with Ruby, you begin by setting up the necessary components. This includes requiring the net/http, uri, and json libraries, which are essential for making HTTP requests and processing JSON-formatted data. You also need to define the URL of your GraphQL API endpoint, which you can find in Hygraph's project settings.

Next, you create an instance of Net::HTTP pointed at your API's URI, handling any necessary configurations like SSL for HTTPS endpoints. You then build your HTTP POST request, setting the appropriate Content-Type and Authorization headers and attaching your query JSON as the request body.

require 'net/http'
require 'uri'
require 'json'
# Your GraphQL API endpoint
url = URI.parse("https://api-<region>.hygraph.com/v2/<some hash>/master")
# Your GraphQL query
query = {
query: '
{
product(id: "1") {
id
name
description
image
availability
}
}
'
}.to_json
auth_token = 'YOUR_HYGRAPH_TOKEN'
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true if url.scheme == 'https'
headers = {
'Content-Type' => 'application/json',
'Authorization' => "Bearer #{auth_token}"
}
request = Net::HTTP::Post.new(url, headers)
request.body = query
response = http.request(request)
data = JSON.parse(response.body)

Step #2 - Work with mutations - store content in the headless CMS

In GraphQL, mutations are how you can modify data on the server, such as creating, updating, or deleting records. When using Ruby to interact with a GraphQL API, mutations are executed similarly to queries, but with a different intent. By crafting a mutation statement and sending it through a POST request, you instruct the server to perform a specific action on your data.

Upon receiving the request, the GraphQL server processes the mutation, carries out the required data manipulation, and returns a response. This response often contains the newly created or updated data object, confirming the changes made.

require 'net/http'
require 'uri'
require 'json'
# Your GraphQL API endpoint
url = URI.parse("https://management.hygraph.com/graphql")
auth_token = "YOUR_HYGRAPH_TOKEN"
mutation = {
query: '
mutation($input: ProductInput!) {
createProduct(input: $input) {
product {
id
name
description
}
}
}
',
variables: {
input: {
name: "New Product",
description: "This is a new product.",
image: "https://example.com/new_product.jpg",
availability: true
}
}
}.to_json
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true if url.scheme == 'https'
headers = {
'Content-Type' => 'application/json',
'Authorization' => "Bearer #{auth_token}"
}
request = Net::HTTP::Post.new(url, headers)
request.body = mutation
response = http.request(request)

Start building with Ruby

We made it really easy to set up your project in Hygraph and use our GraphQL API within your Ruby project.

Quickstart

Check out our docs to see how you can quickly set up your Hygraph project and enable the content API for your Ruby app.

Learn GraphQL

Hygraph is GraphQL-native Headless CMS offers precise data retrieval, minimizing over-fetching and optimizing efficiency.

Examples

Look at some of the example projects to see Hygraph in action.

Why Hygraph

Choosing Hygraph for your Ruby project

Integrating a GraphQL-native headless CMS with Ruby projects boosts efficiency and agility. Ruby's developer-friendly nature complements GraphQL's ability to fetch data with precision, minimizing unnecessary data transfers and optimizing application performance. This setup ensures that Ruby applications are lean and fast, only engaging with the data they need.

Furthermore, a headless CMS separates content from the Ruby code, simplifying content updates without disturbing the application's backend. It enables seamless content flow across various platforms, enhancing scalability and maintainability. By using a GraphQL-native CMS, Ruby applications become more adaptable, allowing developers to focus on innovation rather than backend content management hassles.

ruby cms

Developer Experience

We try to be the most un-opinionated CMS on the market with a wide collection of open source example projects to get you started.

Headless CMS

As a headless CMS (i.e. API based content management), you can be as modular and flexible as you need. We even support multiplatform content management.

Management API

Hygraph boasts a flexible and powerful management API to manage your content and schema, as well as a blazing fast content API.

Get started for free, or request a demo to discuss larger projects