New Devs SAFE Launcher API Tutorial

Hopefully this turns into a joint effort :slight_smile:

EDIT: ADDED JSON SECTION

Been researching more, to be more self sufficient in creating my SAFE apps (relying less on hiring out tasks), and very base level of developing SAFE Apps starts with SAFE Networkā€™s REST APIs, in my opinion. So I am beginning by creating this intro to it all. Here we go!:

API = Application Programming Interface

What is an API? Itā€™s a bunch of easy tools & commands that developers have created to make it easy for your software to communicate with their software.

REST = Representational State Transfer

What is a REST API? Itā€™s the most used type of API. Googleā€™s, Twitterā€™s, Facebookā€™s & other groups APIs all are examples of REST APIs.

How does it work? Very much like a server-based website. Client requests the API, and information is sent back over the HTTP protocol.

Can I see a quick example? Sure! Instead of viewing YTā€™s regular FB page (at www.facebook.com/youtube), go to graph.facebook.com/youtube to create an API call to facebookā€™s servers. It will return a response, over http, in JSON format (more on that below). *May give an error if you arenā€™t properly logged in / authenticated, as common with APIs.

JSON = Javascript Object Notation
Super simple thing. Itā€™s only these 2 things: { ā€œkeyā€ : ā€œvalueā€ } thatā€™s it!!! Best way to send requests for data (or any kind of info), in a super streamlined, efficient format.
Used in APIs alot so you can ask for info easily, like a YouTube API request where you ask for a video key ā€œurlā€ and value : ā€œyt.com/WTf5gā€
Best part, itā€™s JAVASCRIPT (J.S.O.N. the JS = Javascript), so it works perfectly with it. Integrates perfectly. Great news for web apps, where JS is the primary language for all the programming.

Looks like the next step will be simple step-by-step tutorials in various languages, where we execute API commands to the SAFE Network.

3 Likes

Actually, I think the most important is just creating API ā€œcallsā€ using the bare REST API. Then, once people understand that, step #2 should be using ā€œwrappersā€ for other languages (JS, Python, etc).

2 Likes

Iā€™ll fire up Wireshark some time today and see what packets are emitted by the launcher at the start, which will show the protocol.

1 Like

There is no such thing as ā€œbare REST API callsā€. In order to communicate with a RESTful service you need a communication protocol. In our case we use HTTP. But you canā€™t really do bare HTTP calls either. You need a programming language and thatā€™s where you choose Javacript (web or node), python, rust, c++, etc. Maybe I didnā€™t understand you correctly but it seems like you think these programming language are just wrapper over something purer that you should learn first.

My advice is pick a programming language you want to learn. Search how to do an HTTP request and set it up to make the call to a RESTful service. Or pick the code I gave in the other thread and add new calls for all missing features. That should get you started.

You really donā€™t need to fire up Wireshark in order to see the bits going in and out, thatā€™s way too much overkill for starting playing with the SAFE API.

Start small.

2 Likes

And letā€™s agree where we are going to continue this ā€¦

Three competing topics, this one:
New Devs SAFE Launcher API Tutorial
Another started earlier:
ā€˜Hello Worldā€™ SAFE App Example
And the one in the Safenetworkforum also posted in today:
SAFE Network Forum - Help making tutorial apps

3 Likes

Which shows the crazy amount of demand for a super simple tutorial.

Letā€™s get this done then :slight_smile:

1 Like

Gotcha. First time working with them. Thought it was more of a language of itā€™s own, now I see itā€™s more of a set of tools that you use with any language.

1 Like

EDITTED OP to add essential knowledge section on JSON.

Thinking of turning this into a little website or start a blog post of it or something.

Want it to be a resource for brand new devs to get the basic knowledge to get up and running on creating apps for SAFE in the most streamlined way.

Well, with REST (over HTTP(s)) you could always use curl to do stuff :stuck_out_tongue: . Which for a tutorial for developer isnā€™t even that bad, as it is ā€œlanguage agnosticā€ and simple to decipher (and something no one will copy-paste!). They do it at square for their docs, and it is awesome.

3 Likes

Iā€™m going thru the SAFE Dev tutorial and started to play with the Launcher API using Postman; I was actually wondering if anyone has created a Postman collection?
I can otherwise share the collection Iā€™m creating as I study the API, it can perhaps be kept in a shareable location/repo.

6 Likes

I hadnā€™t even heard of this :blush: and AFAIK it hasnā€™t been mentioned by anyone on these forums, so yes pleeeease! It looks great and providing something to help others make use of it would be great.

Thank you :slight_smile:

Ok, I will work on adding more requests to the collection and share it here in the next few days.
Last night I managed to send an email (compatible with the sample email app) using just Postman :wink:

1 Like

Postman is great, thatā€™s a great idea

Almost forgot. Iā€™ll play with it too :slight_smile:

I have a Postman collection ready to share with you which contains the requests necessary to send an email, but I donā€™t know where I should upload it, can you please advise?

1 Like

A github repo probably would work best, perhaps? Nice work, postman is superb for testing APIā€™s and trying stuff out like that. Nice one

2 Likes

Thanks @dirvine. Do you mean within https://github.com/maidsafe or my own repo? (I just donā€™t how you usually handle something like this, Itā€™s ok for me either way)

If you create your own repo thatā€™s cool. We must at some stage collate links to all of these as we go along. I am not sure should we fork them all under a maidsafe community repo and have folks, including us update the code when the APIā€™s are maturing etc.

Anyway your own will be fine for sure. I may start a thread about some kind of way to collate all of these and seek options etc.

5 Likes

Sounds like he meant just make a repo

EDIT: TIL MaidSafe only hires ninjas :slight_smile:

1 Like

Ok, cool, Iā€™ll do that.

EDIT: I just uploaded it here: https://github.com/bochaco/safe-launcher-api-client

Iā€™ll be adding some explanations of how the requests work and how the environment variables are used for each of them.
For the time being this is how it can be used:

  1. Import the collection and the environment variables into Postman
  2. Set the recipientā€™s email id in the ā€œrecipient-email-idā€ environment variable
  3. Execute the requests in the following order:
  • POST /auth
  • GET /auth (optional: to verify it was authorized)
  • GET /appendableData/handle
  • GET /appendableData/encryptKey
  • POST /immutableData (edit the body beforehand, if you want to change the emailā€™s content. Note the time is calculated automatically)
  • GET /immutableData (optional: to verify the DataMapā€™s content)
  • PUT /appendableData/handle
4 Likes

I want to make clear that I am not a ninja :slight_smile: ā€“ neither do I believe any other team member would say that about themselves. While MaidSafe insist on hiring qualified people, most people describing themselves with these terms (ā€œninjaā€, ā€œguruā€, ā€œjediā€ or ā€œrock starā€) usually are not. Quite the opposite, from my experience in this field Iā€™d say that the more experienced the developer, the more humble they become.

3 Likes