{"id":4614,"date":"2019-08-30T17:02:19","date_gmt":"2019-08-31T00:02:19","guid":{"rendered":"https:\/\/blog.caida.org\/best_available_data\/?p=4614"},"modified":"2020-05-13T14:55:10","modified_gmt":"2020-05-13T21:55:10","slug":"as-rank-v2-graphql","status":"publish","type":"post","link":"https:\/\/blog.caida.org\/best_available_data\/2019\/08\/30\/as-rank-v2-graphql\/","title":{"rendered":"AS Rank v2 (GraphQL)"},"content":{"rendered":"<style>\n    .graphql {color:rgb(277,60,170)}\n    .restful {color:rgb(60,177,70)}\n    .code {\n        font-family: monospace;\n        padding-left:.5em;\n        padding-right:.5em;<\/p>\n<p>        white-space: pre;\n        vertical-align:top;\n        background-color:lightgrey;\n        color:black;\n        overflow: scroll;\n    }\n    .code_long {\n        vertical-align:top;\n        height:16.4em;\n    }\n    .query {\n        background-color:black;\n        color:white;\n    }\n    .table_code {\n    }\n    td {\n        vertical-align:top;\n    }\n<\/style>\n<div style=\"margin-bottom:1.8em\">\n<span style=\"font-size:3em\"> <a href=\"https:\/\/asrank.caida.org\"><img style=\"margin-bottom:-13px;height:1.8em\"\n        src=\"https:\/\/asrank.caida.org\/images\/asrank-logo-asr.svg\" alt=\"ASR\"\/><img\n        src=\"https:\/\/asrank.caida.org\/images\/asrank-logo-ank.svg\" style=\"margin-left:-7px;margin-bottom:-8px;height:1.8em\"\n    alt=\"ank\"\/><\/a><span style=\"color:rgb(142,195,232); vertical-align: super;\">v2<\/span><\/span><span style=\"font-size:2em\">(<img style=\"height:.9em;margin-bottom:-5px;\" src=\"https:\/\/www.caida.org\/images\/logo_graphql.png\"><span style=\"color:rgb(227,60,170)\">GraphQL<\/span>)<\/span>\n<\/div>\n<p>\nThe new AS Rank API<sup>v2<\/sup> is ready for use. This new version reflects a move from a <a\n    href=\"http:\/\/as-rank.caida.org\/api\/v1\">RESTful (v1)<\/a> API to a <a href=\"https:\/\/api.asrank.caida.org\/v2\">GraphQL (v2)<\/a> API. This will allow clients to create queries that specify which values they require and contain multiple resources. GraphQL, as a strongly-typed language, allows clients to know what data is available, in what format, and verify responses.\n<\/p>\n<p>\nThe User Interface (UI) can be found at <a href=\"http:\/\/asrank.caida.org\">http:\/\/asrank.caida.org<\/a>. The  Application Programming Interface (API<sup>v2<\/sup>) serves at <a href=\"https:\/\/api.asrank.caida.org\/v2\/graphql\">https:\/\/api.asrank.caida.org\/v2\/graphql<\/a> and GraphiQL interface can be found at <a href=\"https:\/\/api.asrank.caida.org\/docs\">https:\/\/api.asrank.caida.org\/docs<\/a>.\n<\/p>\n<p>\nWe will be operating AS Rank API<sup>v1<\/sup> (<a href=\"http:\/\/as-rank.caida.org\/api\/v1\">http:\/\/as-rank.caida.org\/api\/v1<\/a>) until March 1st, 2020, but it will no longer be updated. Current users should migrate to the v2 API before this date. Contact <a href=\"mailto:asrank-info@caida.org\">asrank-info@caida.org<\/a> for migration assistance.\n<\/p>\n<p>For those unfamiliar with GraphQL, it is a bit of a paradigm shift from the use of a RESTful API, in that <b>GraphQL requires the client to specify precisely which values it needs.<\/b>  In the following example, the client wants to know an ASN&#8217;s transit degree.  With a normal RESTful API, the client must retrieve the full record and extract the information it wants. A GraphQL API client must specify that it wants the ASN&#8217;s transit degree.\n<\/p>\n<table class=\"table_code\">\n<tr>\n<th class=\"graphql\"> GraphQL<\/th>\n<td rowspan=\"99\">\n<th class=\"restful\">RESTFUL<\/th>\n<\/tr>\n<tr>\n<td>\n<table>\n<td class=\"code query\">\n<pre># request ASN 3356's degree\r\nquery={\r\n   asn(asn:\"3356\") {\r\n      asnDegree {\r\n         transit\r\n      }\r\n   }\r\n}\r\n        <\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"code\">\n<pre>data={\r\n   \"asn\": {\r\n      \"asnDegree\": {\r\n         \"transit\": 5255\r\n    }\r\n}<\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<\/td>\n<td>\n<table>\n<tr>\n<td class=\"code query\">\n<pre># request ASN 3356's record\r\n\/asns\/3356?populate=1\r\n                <\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"code\" style=\"max-width:50em\">data={<br \/>\n  &#8220;clique&#8221;: &#8220;true&#8221;,<br \/>\n  &#8220;source&#8221;: &#8220;ARIN&#8221;,<br \/>\n  &#8220;org&#8221;: {<br \/>\n    &#8220;name&#8221;: &#8220;Level 3 Parent, LLC&#8221;,<br \/>\n    &#8220;id&#8221;: &#8220;LPL-141-ARIN&#8221;<br \/>\n  },<br \/>\n  &#8220;cone&#8221;: {<br \/>\n    &#8220;prefixes&#8221;: 516117,<br \/>\n    &#8220;addresses&#8221;: 1293145968,<br \/>\n    &#8220;asns&#8221;: 36019<br \/>\n  },<br \/>\n  &#8220;latitude&#8221;: &#8220;36.0978209554736&#8221;,<br \/>\n  &#8220;rank&#8221;: &#8220;1&#8221;,<br \/>\n  &#8220;country&#8221;: &#8220;US&#8221;,<br \/>\n  &#8220;name&#8221;: &#8220;LEVEL3&#8221;,<br \/>\n  &#8220;country_name&#8221;: &#8220;United States&#8221;,<br \/>\n  &#8220;degree&#8221;: {<br \/>\n    &#8220;peers&#8221;: 95,<br \/>\n    &#8220;globals&#8221;: 5178,<br \/>\n    &#8220;siblings&#8221;: 9,<br \/>\n    &#8220;customers&#8221;: 5083,<br \/>\n    &#8220;transits&#8221;: 5177<br \/>\n  },<br \/>\n  &#8220;longitude&#8221;: &#8220;-91.335620170744&#8221;,<br \/>\n  &#8220;id&#8221;: &#8220;3356&#8221;<br \/>\n}<\/td>\n<\/tr>\n<\/table>\n<\/td>\n<\/tr>\n<\/table>\n<p>\n<b> GraphQL supports mixed record queries.<\/b> The same query can include different record types, and can specify bindings (&#8220;joins&#8221;) between those resources. This approach reduces the number of API queries needed to retrieve related resources.\n<\/p>\n<table class=\"table_code\">\n<tr>\n<th colspan=\"3\" class=\"graphql\"> GraphQL<\/th>\n<\/tr>\n<tr>\n<th> mixed types <\/th>\n<th rowspan=\"999\"><\/th>\n<th> mixed and joined types<\/th>\n<\/tr>\n<tr>\n<td class=\"query code\">\n<pre># request ASN 3356's asnName and \r\n# organization LPL-141-ARIN's rank.\r\n\r\nquery={\r\n   asn(asn:\"3356\") {\r\n      asnName\r\n      organization {\r\n        orgId\r\n      }\r\n   }\r\n   organization(orgId:\"LPL-141-ARIN\") {\r\n      rank\r\n   }\r\n}\r\n        <\/pre>\n<\/td>\n<td class=\"query code\">\n<pre># request ASN 3356's asnName and \r\n# it's organization's rank.\r\n\r\nquery={\r\n   asn(asn:\"3356\") {\r\n      asnName\r\n      organization {\r\n         rank\r\n      }\r\n   }\r\n}\r\n        <\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"code\">\n<pre>data={\r\n    \"asn\": {\r\n      \"asnName\": \"LEVEL3\"\r\n      \"organization\": {\r\n         \"orgId\": \"LPL-141-ARIN\" \r\n      }\r\n    },\r\n    \"organization\": {\r\n      \"rank\": 1,\r\n    }\r\n}\r\n        <\/pre>\n<\/td>\n<td class=\"code\">\n<pre>data={\r\n    \"asn\": {\r\n      \"asnName\": \"LEVEL3\",\r\n      \"organization\": {\r\n        \"rank\": 1\r\n      }\r\n    }\r\n  }\r\n}\r\n        <\/pre>\n<\/td>\n<\/tr>\n<\/table>\n<table style=\"margin-top:-3px\">\n<tr>\n<th class=\"restful\">RESTFUL<\/th>\n<\/tr>\n<tr>\n<th>two separate queries<\/th>\n<\/tr>\n<tr>\n<td class=\"query code\">\n<pre># request ASN 3356's record\r\n\/asns\/3356?populate=1\r\n                 <\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"code\">\n<pre class=\"code_long\">\r\ndata={\r\n  \"name\": \"LEVEL3\",\r\n  \"org\": {\r\n    \"id\": \"LPL-141-ARIN\",\r\n    \"name\": \"Level 3 Parent, LLC\"\r\n  },\r\n  \"clique\": \"true\",\r\n  \"source\": \"ARIN\",\r\n  \"cone\": {\r\n     ...                <\/pre>\n<\/td>\n<\/tr>\n<tr>\n<td class=\"query code\"># request Org LPL-141-ARIN&#8217;s record<br \/>\n\/orgs\/LPL-141-ARIN?populate=1\n                <\/td>\n<\/tr>\n<tr>\n<td class=\"code\">\n<pre class=\"code_long\">\r\ndata={\r\n    \"name\": \"Level 3 Parent, LLC\",\r\n    \"rank\": \"1\",\r\n    \"degree\": {\r\n      \"asn\": {\r\n        \"transit\": 6999,\r\n        \"global\": 7024\r\n      },\r\n      \"org\": {\r\n        ....\r\n                    <\/pre>\n<\/td>\n<\/tr>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>v2(GraphQL) The new AS Rank APIv2 is ready for use. This new version reflects a move from a RESTful (v1) API to a GraphQL (v2) API. This will allow clients to create queries that specify which values they require and contain multiple resources. GraphQL, as a strongly-typed language, allows clients to know what data is [&hellip;]<\/p>\n","protected":false},"author":18,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[1],"tags":[],"coauthors":[27],"_links":{"self":[{"href":"https:\/\/blog.caida.org\/best_available_data\/wp-json\/wp\/v2\/posts\/4614"}],"collection":[{"href":"https:\/\/blog.caida.org\/best_available_data\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.caida.org\/best_available_data\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.caida.org\/best_available_data\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.caida.org\/best_available_data\/wp-json\/wp\/v2\/comments?post=4614"}],"version-history":[{"count":100,"href":"https:\/\/blog.caida.org\/best_available_data\/wp-json\/wp\/v2\/posts\/4614\/revisions"}],"predecessor-version":[{"id":4768,"href":"https:\/\/blog.caida.org\/best_available_data\/wp-json\/wp\/v2\/posts\/4614\/revisions\/4768"}],"wp:attachment":[{"href":"https:\/\/blog.caida.org\/best_available_data\/wp-json\/wp\/v2\/media?parent=4614"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.caida.org\/best_available_data\/wp-json\/wp\/v2\/categories?post=4614"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.caida.org\/best_available_data\/wp-json\/wp\/v2\/tags?post=4614"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/blog.caida.org\/best_available_data\/wp-json\/wp\/v2\/coauthors?post=4614"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}