Result of get endpoint’s resource representation

When I use a HTTP GET method to get a resource representation, the mbed device connector responds like this:

{“async-response-id”:“xxxx#xxxx@xxxx/Test/0/D”}* Connection #0 to host api.connector.mbed.com left intact

What does “async-response-id” mean? How do I get the real value of the given resource?

Hi Max,

When you request for resources of one endpoint, that request is asynchronous and it will be delivered in two steps.

Step 1: You make the request and and get as response from Device Connector an async-response-id that you will be used to map the response afterwards.

Step 2: In the notification channel (that you should have created beforehand), it will come at some point a notification with the async-response-id and the real value of the requested resource. You need to map that notification to the request that you made in step 1 using that async-response-id.

Hope that it helps,
-Enrique

Hi Enrique,

Thanks for your precious reply.

I test mbed-client-examples again with below steps.

  1. Follow the instruction mbed-client-examples - mbed Build instructions to build and prgrogram it to FRDM-K64F board, then connect it to mbed device connector.

  2. Use python flask to run a http server to print the received notification (shown at the bottom).

  3. Register a callback URL.
    curl -v -X PUT -H "content-type: application/json" -H 'Authorization: <application_access_key_xxxx>' https://api.connector.mbed.com/notification/callback -d '{"url":"http://<flask_http_server_ip>:5000/data"}'

  4. Request a resource representation:
    curl -v -H 'Authorization: Bearer <application_access_key>' https://api.connector.mbed.com/endpoints/<endpoint_name>/Test/0/S

  5. flask http server receives this:
    {"async-responses":[{"id":"1745205913#<endpoint_name>@<server_name>/Test/0/S","status":200,"payload":"U3RhdGljIHZhbHVl",,"ct":"text/plain","max-age":60}]}

The payload is “U3RhdGljIHZhbHVl”, it should be “Static value”.
How to decode that value?


####flask http server:

from flask import Flask
from flask import request
from flask import Response

app = Flask(__name__)

@app.route('/data', methods=['PUT'])
def data_received():
    print(request.data)
    return Response(status=204)

if __name__ == '__main__':
    app.run(host="0.0.0.0")

Hi Max,

The value comes B64 encoded. You just need to decode it and it should be it.

After first request, if you make a new request to the same resource it will come from cache (it is cached 60 secs). In that case, you wont receive any async id and the value will be returned straight in Step 1 already decoded.

Hope this helps.

Hi Enrique,

I greatly appreciate your help!

Yeah…the value is B64 encoded.

$ python
>>> import base64
>>> base64.decodestring("U3RhdGljIHZhbHVl")
'Static value'

Regarding this:

After first request, if you make a new request to the same resource it
will come from cache (it is cached 60 secs). In that case, you wont
receive any async id and the value will be returned straight in Step 1
already decoded.

Does it only work for static resources?
Because I tried to issue following command many times within 60 seconds:

curl -v -H 'Authorization: Bearer <application_access_key>' 
https://api.connector.mbed.com/endpoints/<endpoint_name>/Test/0/D

The device connector always responded something like this:

{"async-response-id":"xxxx#xxxx@xxxx/Test/0/D"}* Connection #0 to host api.connector.mbed.com left intact

Best Regards,

  • Max

Hi Max,

Sorry for the delay but I was out last week. About your question, if your device if responding to the request with Max-age=0, then the value is never cached and you will always get async-response.

Can it be the case?

BR,
-Enrique