简体   繁体   中英

Why do my REST calls to IBM Graph take too long (2-4s)?

When I make any call to my IBM Graph instance it takes a couple of seconds for it to complete.

curl "$apiURL/vertices" \
-u "$username:$password"
-X POST \
-H 'Content-Type: application/json' \
-d '{ "Name": "Million Dollar Baby",
      "Type": "Movie" }'

Any idea as to why this happening and if there are any alternatives ?

The reason this is happening is because you're using basic authentication with your rest call. Basic authentication takes longer to authenticate your credentials with every call you make. Basic authentication is good for prototyping or quickly trying something out. Session authentication is the recommended way to use for production code. Here's how it works :

First you need to get a session token using the _session endpoint

#API URL that's returned as part of your credentials 
#without the /g a
curl  -u  username:password  -X GET "<API URL>/_session"

The response should look something like this

{"gds-token":"MzgyZGZmNzEtZTE3MS00ODZlLWIzYzUtN2M2OWI3YTgyYjYxOjE0NTQ1OTc5NTg1NTg6QUp6UmEwTkVJN3I3cFE1Sy9uMHp5ZEZjbmx5YnE5VTJWTjZpM0pnS0ZXVT0="}

Now you can pass this gds-token to subsequent API calls as in the example below

curl -H 'Authorization: gds-token MzgyZGZmNzEtZTE3MS00ODZlLWIzYzUtN2M2OWI3YTgyYjYxOjE0NTQ1OTc5NTg1NTg6QUp6UmEwTkVJN3I3cFE1Sy9uMHp5ZEZjbmx5YnE5VTJWTjZpM0pnS0ZXVT0= Content-Type: application/json' -d '{"Name": "Million Dollar Baby","Type": "Movie" }' -X POST "<API URL>/g/vertices"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM