Consumed REST Services

Last modified: February 19, 2024

1 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 to give 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).

1.1 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.

2 JSON

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

1
2
3
4
5
6
7
8
9
{
	"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.