The JSON message that will be returned is shown bellow and is composed by two temperature measurements. For implementing a real scenario use case, you can check this previous post on how to encode JSON messages with the ESP8266. Each measurement object has a value and a timestamp.įor the sake of simplicity, we are going to have the answer hardcoded in a global variable o the code, so we won’t need to worry about generating it in each request. Basically, the RESP API consists on one endpoint which receives HTTP GET requests and returns a JSON answer composed of multiple measurements. So, our API will simulate a IoT use case, where we will be able to fetch some temperature measurements from the IoT node. The API we are going to expose will be extremely simple, in order to avoid complicating the code, since our main focus is being able to have the Swagger UI on the ESP8266. More details are on the final sections of this tutorial. We are going to specify it in YAML on the Swagger code editor, but we will later convert it to JSON, which is the format that we will be serving on our ESP8266 webserver.Īlthough I’m going to explain all the steps needed to get the final code for the Swagger UI and the API specification in a format suitable to be used in the ESP8266, you may only use the final code as long as you change for the IP of your ESP8266 webserver. We can specify the API both in JSON or YAML. Note that since the Swagger UI needs an API specification to be able to render the content, we will also serve that specification from the ESP8266. So, our objective is to create a very simple REST API on the ESP8266, which will be our HTTP server, create its Swagger specification and add a Swagger UI to it, served by the ESP8266. You can get the Swagger UI from GitHub and you can test an online example here. It can be automatically generated by the previously mentioned Swagger specification for APIs, reducing the effort of documenting it. The Swagger UI is a User Interface that allows users to visualize and interact with the API. Naturally, this is very useful to standardize APIs. Its objective is also to allow users and machines to discover and understand the APIs without needing to have access to the source code implementation or even specific documentation. As a quick explanation, Swagger is a REST API specification that aims to define a standard agnostic to the implementation languages. ![]() The objective of this post is to explain how to add a Swagger UI to a ESP8266 API.Įxplaining what in detail what is Swagger is outside the scope of this post. The objective of this post is to explain how to add a Swagger UI to a ESP8266 REST API.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |