## 5 IoT Platform Communication with IoT Sensors and Applications
### CoAP Versus HTTP  
The term CoAP stands for the Constrained Application Protocol, which is a RESTful web transfer protocol made to ease the translation to HTTP, simplify its web integration, and minimize the HTTP mapping complexity using a low-header overhead, Uniform Resource Identifier (URI), and content-type and CoAP service discovery support. CoAP was produced by the IETF Constrained RESTful Environments (CoRE) working group and was firstly tailored for M2M communication. Comparisons between the performance levels of HTTP and CoAP show that CoAP provides better support for such applications than HTTP (Figure 13). There have been various implementations of CoAP developed through software libraries such as CoAPNET along with C#.NET to develop services that are based on CoAP using Visual Studio on Windows. Figure 11: Client–server communication and CRUD operations in the REST API. Figure 12: REST API. The client requests for a service and the web server calls for it. CoAP is excellent for developers who are familiar with the addressing protocols in web environments and who are using reduced resources while working with limited end devices. It has been shown that on similar hardware, some of the CoAP implementations perform up to 64 times better than HTTP and its equivalents [36]. Unlike CoAP, HTTP is widely known and deployed, so the IETF CoRE Working Group defined a set of guidelines and specifications as the basics of the HTTP-CoAP mapping process. The guidelines are available as RFC 807525 for mapping through the use of proxies. The mapping is not straightforward, and when an HTTP client wants to accesses a CoAP server via HTTP-CoAP, proxy issues during interworking are possible. The issues appear due to the different transport protocols, since HTTP uses TCP while CoAP uses UDP. For this reason, there are mapping schemes defined in the guidelines to map the CoAP and HTTP response codes and different media types in the payloads [36, 47]. For each layer of the whole network application, different protocols are defined. Figure 14 gives a view of the protocols used in CoAP and HTTP network protocol stacks. Figure 15 shows how an HTTP client sends an HTTP request to a CoAP server. The gateway device that hosts the HTTP-CoAP cross-proxy and the CoAP server reside on a sensor-actuator network (SAN) based on IEEE 802.15.4 PHY/MAC. The HTTP request needs to reach the proxy as well as the CoAP server in the SAN, so it includes two host addresses. A resource endpoint name is also needed, so by default it is recommended to map the addresses appending the address of the CoAP resource, for example coap://sex.com/status (accessed on 7 June 2022), to the HTTP-CoAP proxy address [[https://p.ex.com/hc/](https://p.ex.com/hc/)]([https://p.ex.com/hc/](https://p.ex.com/hc/)) (accessed on 7 June 2022), which results in [[https://p.ex.com/hc/coap://sex.com/status](https://p.ex.com/hc/coap://sex.com/status)]([https://p.ex.com/hc/coap://sex.com/status](https://p.ex.com/hc/coap://sex.com/status)) (accessed on 7 June 2022). Figure 14: A CoAP stack compared to an HTTP stack. Figure 13: A performance comparison between CoAP and HTTP. CoAP consumes less power. The requests contain the GET method traversing the client's IPv4 stack, reaching the gateway, traversing the IPv4 stack of the gateway, and finally reaching the proxy. Up to this point, the request is in text format, then it is translated to a CoAP request in a binary format, which has a destination CoAP resource such as coap://s.ex.com/status (accessed on 7 June 2022), after which it is dispatched to the gateway's CoAP stack, which forwards it over the SAN to the end device. The response follows in the reverse towards the gateway [47]. Generally, a server in the REST model enables access to resources, and the client accesses the resources and is responsible for presenting them. The resources are known by their URIs or global IDs. To represent a resource in REST, representations such as text, JSON, and XML are used [48].