Blog
  • AI Gateway
  • AI Security
  • AIOps
  • API Security
  • API Gateway
|
    • API Management
    • API Development
    • API Design
    • Automation
    • Service Mesh
    • Insomnia
    • View All Blogs
  1. Home
  2. Blog
  3. Engineering
  4. Extending Kong Dev Portal With GraphQL
Engineering
June 15, 2021
4 min read

Extending Kong Dev Portal With GraphQL

Sven Walther

Kong Dev Portal comes out of the box with a RESTful API-based catalog and YAML-based template functionality. In this tutorial, I'll show you how to get to the next level of API documentation using Kong Dev Portal with GraphQL. That way, you'll be able to give your API developers an interactive experience.

What You'll Need

In my example, I'll be using Kong Konnect Enterprise Version 2.4, but the version number does not really matter. I also configured my workspace with one service that points to a Star Wars API endpoint with a GraphQL interface (swapi-graphql.netlify.com).

We'll also be using an open source tool called GraphiQL for interactive documentation of a GraphQL endpoint. With GraphiQL, we'll see requests, responses and automated generation of documentation based on the endpoint.

GraphiQL Example


Let's get started.

Create a Template

Since we're starting from scratch, we'll first need to create our template or use one of the layouts that come with Kong out of the box.

Click New File +. Select theme as the file type. We'll enter base/layouts/graphql.html as the file pathname. Right now, this is a very lightweight template. Click Create File.

Kong Dev Portal file theme GraphQL


To add to it, we can include a header and footer by borrowing from what we already have in the graphql.html file we just created. But, for now, we'll just add an H1 that says “Hello World.”

Kong Dev Portal GraphQL Editor

Add Content

Now that we have a template, we need to set up a system that will use it. We need to have content which references this template. Let’s create that file just as we did in the previous step. Change File Type to content. Change the File Path to swapi/index.md. Click Create File.

Kong Dev Portal File Content GraphQL


Edit the file as below and Save Changes:

Kong Dev Portal GraphQL Editor "Hello World"

Edit Title

Now that we have a template rendered, let's make our title visible on the Dev Portal. In our template, we can embed any data in that YAML file we edited earlier. Now it’s rendering "Star Wars" as the title.

Kong Dev Portal GraphQL editor "Star Wars"


Upload the content here and say it’s now about “May the 4th.” We are getting dynamic rendering of content here, and you can put anything in that YAML structure.

Kong Dev Portal GraphQL Editor "May the 4th"

Add an API URL

Let’s go ahead and let’s add a URL. And we will take the URL out of the already existing backend. I’ve already proxied it here using Kong. The URL of our Star Wars API backend is http://localhost:8000/swapi.

So far, we've been entering data. We could display the URL by adding it to the graphql.html file.

Kong Dev Portal GraphQL Editor "May the 4th" with Link

Copy Example Code from GraphiQL

GraphiQL is a JavaScript interface. In Kong, you can use any language in the templates, including HTML, CSS and JavaScript.

From GraphiQL's GitHub, we can copy and paste an example into our template. Change the API URL to the one we set earlier (http://localhost:8000/swapi). Save Changes. Now we have a working GraphQL within our browser.

Kong Dev Portal GraphQL Editor Preview


Before we look at how this renders in the real world, let's change the hardcoding to a variable. We created a variable for that earlier, so we can just put it in here.

This time, I will not use the two curly brackets. This time, I will use a slightly different syntax. The reason for that is that we do not want to encode this in some ways. We all want to have the full URL available in JavaScript. We have many options to parse our data. Let's use page.url like we have done before. Save Changes. It’s now rendering as expected.

Kong Dev Portal GraphQL Editor Preview 2

Test the Interactive Dev Portal

Now we have a running version of GraphQL at localhost:8003/swapi. There are some minor quirks, which we can make nicer, but it’s already fully working.

Kong Dev Portal GraphQL Interactive View

Kong Dev Portal GraphQL Interactive View 2


If we press ▶, we get a response back from the backend system. This portal is a lovely interactive way to work with an API. Everything is pulling from the backend system. We get autocomplete, multivariable and other bells and whistles from the nice graphical endpoint. We got all of this by just copying some JavaScript and HTML into a template. And now we can put as many pages based on that into the system.

Kong Dev Portal GraphQL Interactive View 3

Add a Link to the Navigation

At this point, there's no link to this interactive Dev Portal, so no one can find it. Everything in Kong Dev Portal is declarative, including the navigation. We can change this in the menu structure in our YAML file. You can do much more fancy things, like authentication and role-based access control. Just for this example, adding navigation is enough.

Kong Dev Portal GraphQL Add to Navigation


Once we reload our Dev Portal, we have another endpoint to get to our interactive Star Wars API documentation. Or you could create an overview page where we list all of them. The opportunities are endless.

Kong Dev Portal with Navigation Added

What Will You Create?

This example is just a high-level overview of how much we could do using Kong Dev Portal with GraphQL. We just created an interactive tool that does JavaScript and autocompletes with just a few snippets and the template Kong provides. Kong automates everything else.

Start a free trial, or contact us if you have any questions as you're getting set up.

Once you've set up Kong Dev Portal with GraphQL, you may find these other tutorials helpful:

  • Automating Your Developer Pipeline With APIOps (DevOps + GitOps)
  • Service Design Guidelines Part 2: API Versioning
  • "Gateway Mode" in Kuma and Kong Mesh

Developer agility meets compliance and security. Discover how Kong can help you become an API-first company.

Get a DemoStart for Free
API DocumentationDeveloper PortalTutorialsGraphQL

More on this topic

Videos

The Three-Headed Dragon of Digital Transformation

Videos

Modernizing Legacy APIs with GraphQL, Microservices, and AI

See Kong in action

Accelerate deployments, reduce vulnerabilities, and gain real-time visibility. 

Get a Demo
Topics
API DocumentationDeveloper PortalTutorialsGraphQL
Share on Social
Sven Walther

Recommended posts

GraphQL from the Ground Up

Kong Logo
EngineeringAugust 24, 2023

Building APIs is a craft. Your API product must be stable, accurate, well documented, performant, and meet the informational demands of your clients — no small task. In this series, we'll take a close look at GraphQL , a trending API technology tha

Rick Spurgeon

How to Customize Your Kong Developer Portal

Kong Logo
EngineeringNovember 11, 2021

A developer portal is a storefront to your APIs (the products) that internal and external developers are trying to consume. The Kong Developer Portal provides a single source of truth for all developers to locate, access and consume services. With

Sven Walther

Kong-plement Your ServiceHub With a Dev Portal

Kong Logo
EngineeringAugust 5, 2021

Two of the best (in my opinion) features in Konnect are the ServiceHub and Dev Portal. However, they're also two of the most misunderstood. Aren't they the same thing? Why would you need a ServiceHub vs. Dev Portal? Well, I'm glad you asked! The r

Michael Heap

Top Docker Desktop Extensions for Developers and How to Use Them

Kong Logo
EngineeringSeptember 26, 2024

For the last 10+ years, Docker has been one of the leading technology tools for helping developers build, run, update, and manage containers. It is one of the most widely used containerization tools available, able to work with Linux, Microsoft Wind

Kong

How to Craft and Sign a Custom JWT in Kong Konnect

Kong Logo
EngineeringJune 18, 2024

The JSON Web Token (JWT) is an open standard that allows information to be transferred securely between different parties. The token is digitally signed by using a private key (HMAC) or a public/private key (RSA) by building a JSON Web Signature (JW

Jerome Guillaume

Manage API Access More Seamlessly

Kong Logo
EngineeringMarch 1, 2024

The Kong Konnect team recently launched the Portal Management API , which allows users to manage their Developer Portals with one API. That means you can easily manage your portal settings, appearance, application registrations, and registration se

Ella Kuzmenko

Docs as Code: Screenshot Automation at Kong

Kong Logo
EngineeringOctober 24, 2023

Imagine this: You're documenting an unreleased feature, and your documentation requires screenshots. However, you're working in an internal environment that includes features you don't want to reveal to the public. What do you do? We faced this exac

Angel Guarisma

Ready to see Kong in action?

Get a personalized walkthrough of Kong's platform tailored to your architecture, use cases, and scale requirements.

Get a Demo
Powering the API world

Increase developer productivity, security, and performance at scale with the unified platform for API management, AI gateways, service mesh, and ingress controller.

Sign up for Kong newsletter

    • Platform
    • Kong Konnect
    • Kong Gateway
    • Kong AI Gateway
    • Kong Insomnia
    • Developer Portal
    • Gateway Manager
    • Cloud Gateway
    • Get a Demo
    • Explore More
    • Open Banking API Solutions
    • API Governance Solutions
    • Istio API Gateway Integration
    • Kubernetes API Management
    • API Gateway: Build vs Buy
    • Kong vs Postman
    • Kong vs MuleSoft
    • Kong vs Apigee
    • Documentation
    • Kong Konnect Docs
    • Kong Gateway Docs
    • Kong Mesh Docs
    • Kong AI Gateway
    • Kong Insomnia Docs
    • Kong Plugin Hub
    • Open Source
    • Kong Gateway
    • Kuma
    • Insomnia
    • Kong Community
    • Company
    • About Kong
    • Customers
    • Careers
    • Press
    • Events
    • Contact
    • Pricing
  • Terms
  • Privacy
  • Trust and Compliance
  • © Kong Inc. 2025