Turn Your StepZen GraphQL APIs into REST with Kong

Turn Your StepZen GraphQL APIs into REST with Kong

Why turn GraphQL APIs (back) into REST?

Using Kong to turn GraphQL APIs into REST APIs

# https://graphqldd.stepzen.net/api/dd1cf47f51ac830fe21dc00ec80cee65/__graphql
query ConvertCurrencyByIP ($amount: Float!, $from: String!, $ip: String!) {
converted: ipApi_location(ip: $ip) {
countryCode
price: priceInCountry(amount: $amount, from: $from)
}
}
curl 'https://graphqldd.stepzen.net/api/dd1cf47f51ac830fe21dc00ec80cee65/__graphql' \
-H 'authority: graphqldd.stepzen.net' \
-H 'accept: application/json' \
-H 'content-type: application/json' \
--data-raw $'{"query":"query ConvertCurrencyByIP($amount: Float\u0021, $from: String\u0021, $ip: String\u0021) { converted: ipApi_location(ip: $ip) { countryCode price: priceInCountry(amount: $amount, from: $from) } }","variables":{"amount":100,"from":"GBP","ip":"8.8.8.8"},"operationName":"ConvertCurrencyByIP"}' \
curl http://localhost:8000/price/ \
--header "Content-Type: application/json" \
--data '{"query": "query ($amount:Float!,$from:String!,$ip:String!){converted:ipApi_location(ip:$ip){countryCode price:priceInCountry(amount:$amount,from:$from)}}", "variables": {"amount":100,"from":"GBP","ip":"8.8.8.8"}}'

{
"data": {
"converted": {
"countryCode": "US",
"price": 115.69
}
}
}
curl -X POST http://localhost:8001/services/graphql-demo/degraphql/routes \
--data uri="/gbp/:ip/:amount" \
--data query='query($amount:Float!,$ip:String!){converted:ipApi_location(ip:$ip){countryCode price:priceInCountry(amount:$amount,from:"GBP")}}'
curl localhost:8000/price/gbp/8.8.8.8/100

{
"data": {
"converted": {
"countryCode": "US",
"price": 115.69
}
}
}
curl localhost:8001/services/graphql-demo/plugins -d name=jq -d config.response_jq_program='.data' -d config.request_if_media_type='application/json; charset=utf-8'
curl localhost:8000/price/gbp/8.8.8.8/100

{"converted":{"countryCode":"US","price":115.69}}

Conclusion

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Roy Derks (@gethackteam)

Roy Derks (@gethackteam)

1K Followers

Roy is an entrepreneur, speaker and author from The Netherlands. Most recently he wrote the books Fullstack GraphQL and React Projects.