Event and Query URLs with Postman

Contents:

What is Postman?

Postman is used by developers to easily send API request and it is a great tool used by many to test their API request responses. Postman makes it easy to automate test and create an organized workspace for you to test your API. Through their desktop client you can send any type of http request which you may find useful when wanting to test events and queries on a pico.

For more information: https://www.postman.com/

Download: https://www.postman.com/downloads/

Raising an Event on Postman

Step 1:

Create a Request Tab

Step 2:

Change Request Method to POST

Step 3:

Choose the pico for which you want to raise a rule

For this example we will use the following rule found in io.picolabs.wrangler:

Rule: createChild

Domain: wrangler

Type: child_creation

Step 4:

Find your ECI

Go to the pico’s “Channels“ tab and here you can find the different ECI’s (Event Channel Identifier) that the pico currently has. Choose an ECI with an appropriate policy id. In our example we are using the ECI with policy id of “allow-all-policy“ and type “wrangler“.

Step 5:

Build your request URL

Following the events and queries lesson, you will want to build a URL for raising an event:

<protocol>://<host>:<port>/sky/event/<eci>/<eid>/<domain>/<type>

In this example we will be using the following for the different components:

protocol: http

host: localhost (running the pico engine locally)

port: 8080

eci: JmMTv2vMt1hKTRtyNcfUYB

eid: child_test

domain: wrangler

type: child_creation

So our URL should look like this:

http://localhost:8080/sky/event/JmMTv2vMt1hKTRtyNcfUYB/child_test/wrangler/child_creation

You can now place the request URL in the designated input field in Postman

Step 6:

Create request body

To create the request body, you are going to want to do the following:

  1. click on the “Body“ tab

  2. select the “raw“ bullet

  3. choose JSON as the datatype

In the text block field you can now create your JSON body request like so

Step 7:

Send request and confirm result

You can send the request by hitting the “Send“ button

 

 

After hitting “Send“ you can now see the response below where you wrote the request body

You can see that the response contains directives that let me know that the child pico was created.

Querying a Pico on Postman

Step 1:

Create a Request Tab

Step 2:

Change Request Method to GET

Step 3:

Choose which pico, ruleset and function you want to query

Looking at your pico engine UI, decide which pico, which ruleset, and which function you want to query. I chose my ‘bus’ pico and the ‘uta_time’ ruleset. The function from this ruleset I chose is the ‘dayOfWeek’ function. Be sure the ruleset shares the function you want to test, otherwise you will get a 500 status when you query it along with the message “Not Shared”.

Step 4:

Find your ECI

Inside the pico that you want to query, go to the channels tab. Select an ECI with an appropriate policy.

Step 5:

Build your URI

Following the events and queries lesson, you will want to build a query url following this pattern:

<protocol>://<host>:<port>/sky/cloud/<eci>/<rid>/<function>

In this example we will be using the following for the different components:

protocol: http

host: localhost

port: 8080

eci: KZv4wR1NzmdPxCCS9oxw7i

rid: uta_time

function: dayOfWeek

Our url should look like this:

http://localhost:8080/sky/cloud/KZv4wR1NzmdPxCCS9oxw7i/uta_time/dayOfWeek

Step 6:

Add parameters

My dayOfWeek function takes an optional argument called “decorator” which I can include by adding it to the end of the request in a query string. More information on query strings can be found here.

Step 7:

Confirm result

After clicking send, I can confirm that the response is correct. On this day it was Thursday, and the decorator from the query string was passed in as a parameter.

Copyright Picolabs | Licensed under Creative Commons.