Last active
September 1, 2022 12:17
-
-
Save lonniev/6c9c827fd1797cb7d0d3b32385c698c3 to your computer and use it in GitHub Desktop.
Perform a Gremlin Query which makes an authenticated REST call during one Step
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
signInToken = { -> signInPost = new URL( "http://some.host.com:9000/signIn" ).openConnection(); message = '{ "username": "[email protected]", "password": "my-password", "rememberMe": false }'; signInPost.setDoOutput( true ); signInPost.setRequestProperty( "Content-Type", "application/json" ); signInPost.getOutputStream().write( message.getBytes( "UTF-8" ) ); signInPost.getResponseCode(); j = new groovy.json.JsonSlurper().parseText( signInPost.getInputStream().getText() ); j.resources.token } | |
userName = { u,t -> userGet = new URL( "http://some.host.com:9000/users/${u}" ).openConnection(); userGet.setRequestProperty( "Accept", "application/json" ); userGet.setRequestProperty( "X-Auth-Token", t ); userGet.getResponseCode(); j = new groovy.json.JsonSlurper().parseText( userGet.getInputStream().getText() ); j.resources.name } | |
g.V().limit(1).map { it -> userName( it.get().value( 'modifiedBy' ), signInToken() ) }.find() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It is always important to remember that Lambda steps are significantly slower than Gremlin-internal steps. Make sure to only "call out" for additional details with small datasets only when necessary.