HTTP

Last updated: Mar 5th, 2018

Introduction

The HTTP system operation provides the developer with the option to make HTTP/S requests. The purpose of this is to access data from external APIs

var request = new HTTP;

Temporary Limitations of the HTTP System Operation

The HTTP system operation currently supports responses which provide data in JSON format. Support for XML, and plain text responses are under development.

Properties

method

Type: string

The HTTP request method. The following methods are currently supported by Cuneiform.

  • get
  • post
  • put
  • delete

url

Type: string

The url if the resource the HTTP/S request is intended to be sent to.

data

Type: object

Data being sent along with the HTTP/S request. This data is converted from a Cuneiform object into JSON, and is sent as a JSON payload.

An example of making a request to an external API can be found in the PizzaShop sample application. The http properties are provided as follows:


var orderData = {
    name : typeName,
    crust : selectedCrust,
    size : selectedSize,
    address : address,
    time : dateTime
};
var http = new HTTP;
http.method = "post";
http.url = "https://pizzashop-sample.herokuapp.com/api/order/add";
http.data = orderData;
                                    

Operations

request

Return type: object

Makes an HTTP/S request using the properties provided.

Obtains the HTTP response as a JSON value, converts it to a Cuneiform object and returns it.

What's next?

The next part discusses the implementation of the HTTP system operation.