Consumed REST Services

Last modified: August 20, 2024

REST

Representational state transfer (REST) is an approach to consuming or exposing resources. It has gained popularity because of its simplicity, because no extensive schemas or contracts are needed to transfer data between endpoints. It uses the following:

  • HTTP URLs to locate resources
  • HTTP headers to authenticate and specify content types (such as XML or JSON)
  • HTTP methods to identify operations on resources, such as GET (retrieve data) or POST (send data)

Lack of contracts and schemas give you an easy start to using REST. However, many REST endpoints return complex data.

The JSON Structure document helps with giving structure to JSON data: from an example JSON snippet, a lightweight schema is extracted that is used in Mapping Documents. The Import Mapping document converts JSON (or XML) to Mendix objects, and the Export Mapping document serializes Mendix objects to JSON (or XML).

Content Types

Content types are included in custom HTTP headers to specify the output of the call, including media type or data format. For more information on content types, see Content Negotiation in REST.

JSON

JavaScript object notation (JSON) is a lightweight representation of data.

{
	"name": "John Smith",
	"age": 23,
	"address": 
	{
		"street": "Dopeylane 14",
		"city": "Worchestire"
	}
}

Above, the object person is described with the corresponding values for the attributes name, age, and the referred object address.

REST calls that output JSON need to declare the content type as application/JSON.