AS Rank v2 (GraphQL)

August 30th, 2019 by Bradley Huffaker
ASRankv2(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 available, in what format, and verify responses.

The User Interface (UI) can be found at http://asrank.caida.org. The Application Programming Interface (APIv2) serves at https://api.asrank.caida.org/v2/graphql and GraphiQL interface can be found at https://api.asrank.caida.org/docs.

We will be operating AS Rank APIv1 (http://as-rank.caida.org/api/v1) until March 1st, 2020, but it will no longer be updated. Current users should migrate to the v2 API before this date. Contact asrank-info@caida.org for migration assistance.

For those unfamiliar with GraphQL, it is a bit of a paradigm shift from the use of a RESTful API, in that GraphQL requires the client to specify precisely which values it needs. In the following example, the client wants to know an ASN’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’s transit degree.

GraphQL RESTFUL
# request ASN 3356's degree
query={
   asn(asn:"3356") {
      asnDegree {
         transit
      }
   }
}
        
data={
   "asn": {
      "asnDegree": {
         "transit": 5255
    }
}
# request ASN 3356's record
/asns/3356?populate=1
                
data={
“clique”: “true”,
“source”: “ARIN”,
“org”: {
“name”: “Level 3 Parent, LLC”,
“id”: “LPL-141-ARIN”
},
“cone”: {
“prefixes”: 516117,
“addresses”: 1293145968,
“asns”: 36019
},
“latitude”: “36.0978209554736”,
“rank”: “1”,
“country”: “US”,
“name”: “LEVEL3”,
“country_name”: “United States”,
“degree”: {
“peers”: 95,
“globals”: 5178,
“siblings”: 9,
“customers”: 5083,
“transits”: 5177
},
“longitude”: “-91.335620170744”,
“id”: “3356”
}

GraphQL supports mixed record queries. The same query can include different record types, and can specify bindings (“joins”) between those resources. This approach reduces the number of API queries needed to retrieve related resources.

GraphQL
mixed types mixed and joined types
# request ASN 3356's asnName and 
# organization LPL-141-ARIN's rank.

query={
   asn(asn:"3356") {
      asnName
      organization {
        orgId
      }
   }
   organization(orgId:"LPL-141-ARIN") {
      rank
   }
}
        
# request ASN 3356's asnName and 
# it's organization's rank.

query={
   asn(asn:"3356") {
      asnName
      organization {
         rank
      }
   }
}
        
data={
    "asn": {
      "asnName": "LEVEL3"
      "organization": {
         "orgId": "LPL-141-ARIN" 
      }
    },
    "organization": {
      "rank": 1,
    }
}
        
data={
    "asn": {
      "asnName": "LEVEL3",
      "organization": {
        "rank": 1
      }
    }
  }
}
        
RESTFUL
two separate queries
# request ASN 3356's record
/asns/3356?populate=1
                 
data={
  "name": "LEVEL3",
  "org": {
    "id": "LPL-141-ARIN",
    "name": "Level 3 Parent, LLC"
  },
  "clique": "true",
  "source": "ARIN",
  "cone": {
     ...                
# request Org LPL-141-ARIN’s record
/orgs/LPL-141-ARIN?populate=1
data={
    "name": "Level 3 Parent, LLC",
    "rank": "1",
    "degree": {
      "asn": {
        "transit": 6999,
        "global": 7024
      },
      "org": {
        ....
                    

Leave a Reply