How do i build a client for my API?


I’d like to build a CLI for an API. I first want to implement the authentication process.
In curl, i first need to create a session token:

$ curl -X GET -H 'Content-Type: application/json' -H 'Authorization: user_token jlev3v39zgiplrgo1cvj3vvv9r13viqf45a61dezt' '' {"session_token":"bilkabrilblroj05lr3fe4dem2"}

Then i can use the token to resquest the API:

$ curl -X POST -H 'Content-Type: application/json' -H "Session-Token: bilkabrilblroj05lr3fe4dem2" {"4":{"name":"admin","role": "admin"}}

How do i do that in Go? Can you point me to clients source code that use a similar API?

Thank you.

Hey @humboldtux,

If you want to convert curl to Go code, you should check out by @matt.

Thank you @radovskyb, that is a start, even if i’m more looking for a similar project on how to create the client, the session, handling request.

Hey @humboldtux, if you give me a small walk down of the process you’re trying to implement, I or somebody else can help you find some resources to learn, or I can even just help you put something small together with some annotations to help you learn how it works if you’d like.

1 Like

i guess that what you need is a golang http client (see net/http package). an example is here.

1 Like

@geosoft , @radovskyb thank you for your help.

I didn’t find time to work on this. I will post as soon as i have something to show.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.