GraphQL API for Netbox

946 views
Skip to first unread message

Chris

unread,
May 17, 2017, 6:07:03 AM5/17/17
to NetBox
Hi

The API of Netbox is a great way to integrate Netbox into processes and tools. But sometimes, the API feels too verbose, while at other times it feels too restrictive. Other (big) vendors of software products with have recognised that same problem as well and set out to find a solution. Facebook eventually came up with GraphQL, and some well-known companies followed, such as Github and Shopify.

Using a regular REST API versus using a GraphQL API is very different. A regular REST API, as currently found in Netbox, uses the URL to address which entities it returns. It also defines with little flexibility with wich level of detail the results are returned. For example, let's look at a query for an interface: The result contains all information about the interface, some information on the device, the connection and the connected interface. Furthermore, the connected interface embeds more data, whereas the device doesn't. Would I require more information on the device, I'd had to query the API once more.

With GraphQL however, the client has to send an exact query to the server in which he defines the answer which he likes to receive. Would I, for example, want to retrieve all the interfaces, with their corresponding devices and including each device's asset tag, I'd send a query like the following:

{
  interfaces {
    name
    device {
      name
      display_name
      asset_tag
    }
  }
}


It would return a JSON which exactly contains the data that was requested.

Because I think Netbox would profit a lot from such an API, I asked a coworker to look into the possibilities of adding GraphQL to Netbox. His conclusion was that it's feasible but that there are, of course, certain challenges (like traversing where there's no explicit relation, i.e. prefixes <> IPs). He also did not yet look into modifying Netbox's entities through GraphQL. The interested party can look into our PoC at our fork on Github [2]. The main changes so far were pretty much straight-forward [3].

We might be able to drive the implementation forward, primarily because it looks like we ourselves could profit a lot from such an API. But at some point we would want to hand over the code into mainline Netbox. Hence, before putting a lot of work into this, it's crucial to us that such a contribution is welcomed by the community and Netbox's maintainers, i.e. Jeremy.

So, who else would be interested in seeing that kind of API? What are your thoughts/experiences on it? And what's your opinion on it, Jeremy?

Kind Regards,
Chris

PS: To use our PoC, start Netbox from our branch in your preferred environment and navigate to 'http://your_netbox/graphql'.

Jeremy Stretch

unread,
May 17, 2017, 12:33:34 PM5/17/17
to Chris, NetBox
> And what's your opinion on it, Jeremy?

I released NetBox v2.0 just last week after spending several months developing the new REST API. I hope you'll understand that it will be quite a while before I'll be interested in making any major changes to it. Maybe this is something to revisit for version 3.0, probably sometime next year.

Jeremy

--
You received this message because you are subscribed to the Google Groups "NetBox" group.
To unsubscribe from this group and stop receiving emails from it, send an email to netbox-discuss+unsubscribe@googlegroups.com.
To post to this group, send email to netbox-discuss@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/netbox-discuss/2c31e58f-0932-4e2e-a4b3-8bdfeb4a8517%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages