Last active
July 10, 2023 01:08
-
-
Save KartikBazzad/1cc121208f03a29f331deb62f5b86e49 to your computer and use it in GitHub Desktop.
Config Schema and Parsing Token System
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| What this is about? | |
| Ans: i am building an music application that takes an config file, that will have a unified schema design and endpoints user can use, the endpoints and their responses can be different for each user, to make it simple i was thinking of making a parsing system, and then parse and use the endpoints and use mappings values to map responses according to our classes/models | |
| there will be other endpoints for song, playlist, album, search, genre | |
| Depending on the endpoints user provides , we show certain ui widgets, | |
| The home,song,playlist endpoint are required | |
| response_key : key name from response object | |
| attribute: key name in our modals | |
| CONFIG FILE config.yaml START | |
| version: 0.0.1 | |
| base_url: "base_url" | |
| endpoint_names: | |
| - home | |
| endpoints: | |
| home: | |
| name: "home" | |
| url: "/home" | |
| method: "GET" | |
| headers: | |
| - key: key | |
| value: value | |
| response_object: "object:data:array_map" | |
| mappings: | |
| - response_key: "title" | |
| attribute: "title" | |
| - response_key: "contents" | |
| attribute: "contents" | |
| schema: "contents" | |
| function: | |
| name: "array_map" | |
| conditions: | |
| - key: "videoId" | |
| type: "song" | |
| - key: "playlistId" | |
| type: "playlist" | |
| - key: "browseId" | |
| type: "album" | |
| schema: | |
| contents: | |
| name: "contents" | |
| mappings: | |
| - response_key: "title" | |
| attribute: "title" | |
| - response_key: "thumbnails" | |
| attribute: "thumbnailUrl" | |
| format: "array:-1:object:url" | |
| - response_key: "videoId" | |
| attribute: "songId" | |
| - response_key: "browseId" | |
| attribute: "albumId" | |
| - response_key: "playlistId" | |
| attribute: "playlistId" | |
| CONFIG FILE config.yaml END | |
| # Token System for mapping and processing the response from api endpoints | |
| # ex: data_type:value | |
| # tokens for single Item from Arrays: | |
| # use the format key from the schema | |
| # if array of string= array:index_value | |
| # if array of objects= array:index_value:object:key_name | |
| #tokens Objects: | |
| # if object = object:key_name | |
| # if object and value of key is array = object:key_name:array:index_value // if the value is array we apply parsing for array; | |
| # Functions: | |
| # function: | |
| # name: name of function | |
| # | |
| # | |
| # - array_map Perform array Map method on the array and map the items with schema key provided | |
| # - fetch perform fetch operation with the given details | |
| # example: | |
| # function: "fetch" | |
| # fetch: | |
| # url: string | |
| # baseUrl: string | |
| # headers: | |
| # - key: header_key | |
| # value: header_value | |
| # query_parameters: | |
| # - key: query_name | |
| # value: query_value | |
| # | |
| # | |
| # | |
| #conditions: can be use to determine the items Like: if item has key songId use Song class, | |
| # key: key_name | |
| # type: ClassName | |
| # | |
| # eg: key: songId | |
| # type: Song | |
| # | |
| # | |
| #Schema: section section describes schema that can be used to map response when using functions, it takes a name and list of mappings | |
| # For eg: contents: | |
| # name: "contents" | |
| # mappings: | |
| # - response_key: "title" | |
| # attribute: "title" | |
| # - response_key: "thumbnails" | |
| # attribute: "thumbnailUrl" | |
| # format: "array:-1:object:url" | |
| # - response_key: "videoId" | |
| # attribute: "songId" | |
| # - response_key: "browseId" | |
| # attribute: "albumId" | |
| # - response_key: "playlistId" | |
| # attribute: "playlistId" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment