Http Blueprint Example

Walk through of how to use the Http nodes to call an existing MSquared web platform api

Let's call an MSquared Web Platform API to retrieve your profile. Whilst this functionality already exists in the system, it serves as a simple example to demonstrate how we can use the Http nodes.

Fetching Data via Get

We need to call the web platform profile api via GET. The url listed in the web platform documentation is

A json version of the response data we would get back looks like:

 "username": "somebody"

Create a Blueprint Struct

First we need a struct to hold the data that the web platform returns. As a bare minimum we need a Username property that's of string type.

I called my struct SM2_ProfileApiResponse, but you can call it whatever you like

Create a Morpheus Actor Component for your Logic

Create a component for your test or use an existing one. I won't cover how to do that here, as there's plenty of examples in the rest of the documentation.

For our purposes we need to add a node to issue the request and some nodes to deal with the responses.

Let's break this down into steps:

Drop in a Http Get Json node and configure it:

  • Url: /api/profile

  • Auth Context: Self

  • Scope: Organization

The url from the request is obtained from the MSquared Web Platform docs; the key here is that we stripped off the domain from the docs to keep just the path.

In order for the JSON response to be deserialized into your struct, we need an instance of it. The simplest way of doing this is to have a variable in your Blueprint (or function). Make sure the variable is of the type you defined your response data as.

The next step after configuring the Http node is to deal with the data you get back. For this, we will use the "Read Json Object Into Struct" node. This node requires a Json Object and an input of the struct to be populated. This struct needs to exist already, which is why we made it a variable earlier.

Once this node has executed, the Response Data variable should contain your profile name. You can validate it by printing to screen.

Modifying Data via Post/Put/Patch

Now we've been able to fetch data, let's use the same principles to modify some data. In this example, let's modify your profile name.

We need to call the web platform profile api via PUT. The url listed in the web platform documentation is the same as before, just the method changes to PUT.

A json version of the request data we need to send looks like this:

 "username": "somebody"

In this example we could use the same Blueprint Struct as the response we used earlier, but it's often best practice to keep them separate as things can change over time.

Let's go head and define a new struct SM2_ProfileApiPutRequest

Now let's hook up the events:

The first thing to do is make an instance of your request struct. For this we can just use the "Make SM2_ProfileApiApiRequest" node that Blueprint gives us.

Set a value for your new name on the struct. Here we called it "new name".

Next we use the "Make Json Object From Struct" node to take in your struct and output a Json Object.

This Json Object can then be used as an input in the "Http Put Json" node.

Configure the Http Put Json node in the same way as before:

  • Url: /api/profile

  • Auth Context: Self

  • Scope: Organization

Now we can use the "On Success" control pin to the nodes we made before.

Running this should change your profile name to "new name" and post this to screen.

Last updated