Open event server has two types of API (Application Programming Interface) formats, with one being generated by the legacy server and other one by the server side of decoupled development structure. The open event web app supported only the new version of API format, thus an error in read contents of JSON was thrown for the old version API format. To enable the support for both kind of API formats such that web app can be generated for each of them and there is no need to convert JSON files of version v1 to v2 we added an option field to the generator, where the client can choose the API version.
Excerpts and description for difference between data formats of API v1 and v2
The following excerpt is a subprogram getCopyrightData in both versions v1 and v2. The key for getting licence details in v1 is ‘licence_details’ and in v2 is ‘licence-details’. Similarly the key for getting copyright details in v1 is ‘copyright’ and in v2 is ‘event-copyright’.
So the data is extracted from the JSON files depending on the API version, the client has selected.
Another example showing the difference between the API formats of v1 and v2 is excerpted below.
The following excerpt shows a constant ‘url’ containing the event URLs and the details. The version v1 uses event_url as a key for the main page url whereas v2 uses event-url for getting the same. A similar kind of structural difference is present for rest of the fields where the special character underscore has been replaced by hyphen and a bit of change in the name format for keys such as start_time, end_time.
How we enabled support for both API formats?
To add the support for both API formats we added a options field on generator’s index page where the user chooses the type of API format for web app generation.
The generator depending on the version of API format, chooses the correct file where the data extraction from the input JSON files takes place. The file names are fold_v1.js and fold_v2.js for extraction of JSON v1 data and JSON v2 data respectively.
The excerpts of code showing the difference between API formats of v1 and v2 are the contents of fold_v1.js and fold_v2.js files respectively.
- Open Event Webapp Repository: https://github.com/fossasia/open-event-webapp
- Pull Request: https://github.com/fossasia/open-event-webapp/pull/1765
- Issue : https://github.com/fossasia/open-event-webapp/issues/1759
- API format v1: https://eventyay.com/api/v1/
- API format v2: http://open-event-api.herokuapp.com