OPEN API Spec - Global Standard. Generated Code
Posted February 18, 2022 by Handi Deyana ‐ 3 min read
One of protocol to connect mobile app to server is via REST API. But it is not always easy to write code for REST API. It requires knowledge of HTTP and JSON. And to integrate between backend and mobile app require some code.
Common conflict or drama when integration happen
- Wrong TYPE!, int become string, boolean become 1 or 0. Etc
- Wrong Method, GET/POST, POST or PUT?
- Typo when request
- No Standard
Most of conflict happen cause human error, communication, and no standard applied when integration happen.
OPEN API Spec
The OAS defines an open standard for RESTful APIs, which is a specification for how to use HTTP requests and responses to communicate with web services. The OAS provides guidance on how to structure an API, as well as how to interact with it using HTTP requests and responses. The OAS also describes how to generate code that can be used to interact with the API.
The spec will make standard for
- Standard HTTP Status Code
- How response data component like
- HTTP Security Standard
And other standard you can found out here
Integration with spec
This simple diagram show how integrate with Rest API and use it in mobile application
How it look in code
Number of line of code in our code base.
|Line Of Code|
|Not using generator||>100 line|
|Using generator||14 line|
Code generator are done with open-api-generator is a tool to generate the OpenAPI specification for an existing RESTful API. We can generate to those:
Find out about code generation on Github or their website
The time it took to write function, write model, and define how to integrate. With Generated Code from Open API anyone don’t have to write it again.
In fact we don’t have to maintain the code of network integration. If something bad happens in generation tool, worry less since Open API Spec are open global standard. and code generator tool are open source mean that everyone can contribute, make issue, and make copy of existing tool.
Tech change often when there are new tool to build mobile app and we migrate to it, the current spec are same and we can reuse the generated code. So we don’t have to write network integration again.
To implement open api is team effort. We need to work together, discuss and make decisions. I Hope that everyone can understand the good impact of OPEN API Standard
You can learn about OPEN API here
OPEN API Spec and generated code will make easier to integrate between server and mobile app. Cause it add standard to api. I hope it become standard to consume Rest API across MNC GROUP.