Skip to main content

httprequest

Availability

Agent

Description

The HTTPRequest class represents a single HTTP (client) transaction. A new httprequest object is returned from each call to http.get(), http.post(), http.put() and similar methods.

This object should not be confused with the request table passed into the HTTP request handler callback that is registered using http.onrequest(). An httprequest object embodies a transaction that will be sent by the agent; the HTTP request handler callback’s request parameter is a table of decoded data from a transaction that has been received.

Each httprequest object is a ‘one shot’: to perform a further request, call http.get(), http.post(), http.put() or similar once again to obtain a fresh httprequest object.

Rate-Limiting

The number of requests you can make is rate-limited. Available request credits are shared among httprequest and httpstream. You have credit for a total of 40 requests of any type, ie. if you issue 20 httpstreams you can only issue 20 httprequests until your credits are replenished. As requests are issued they regenerate at the rate of two credits per second, up to the maximum of 40. This allows you to make 120 requests in 60 seconds, issuing up to 40 at any one time.

  • You can find a list of HTTP request response codes with specific meanings for imp-enabled devices here.

Example Code

For sample code that can be used to manage messaging between agents and the Internet, see the imp API Cookbook recipes ‘Basic Agent-to-Internet Communications’ and ‘Long-polling Agent-to-Internet Communications’.

Member Entities

The httprequest object has the following member methods: