Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Route REST URL to parsed data #8

Open
4 tasks
FarazzShaikh opened this issue Jun 25, 2021 · 1 comment
Open
4 tasks

[Core] Route REST URL to parsed data #8

FarazzShaikh opened this issue Jun 25, 2021 · 1 comment
Assignees
Labels
no-firebase Does not require Firebase to-do
Milestone

Comments

@FarazzShaikh
Copy link
Contributor

Route REST URL to parsed data

We must parse a URL to is appropriate resource. Here is what the URL would look like.

https://api/<USER_ID>/<RESOURCE_ID>/<SELECTOR>

Here is what the resources look like in the DB.

USER_ID: {
  RESOURCE_ID: {
    SELECTOR: Array<Object>,
    SELECTOR: Array<Object>,
    SELECTOR: Array<Object>,
    SELECTOR: { 
        SELECTOR: Array<Object>, 
        SELECTOR: Array<Object> 
    }
    ...
  },
  RESOURCE_ID: { ... },
  ...
}
  • USER_ID: Ignore for now. Fix that to the value UserA
  • RESOURCE_ID: Id of the webpage to access.
    - SELECTOR: The specific selector to access.

Here is what an Array<Object> looks like in the DB.

[
    {
        "tag":  <TAG_TYPE>,
        "data": <TEXT_CONTENT>,
        "attributes": {
                <ATTRIBUTE_KEY>: <ATTRIBUTE_VALUE>,
                  ...
         }
     },
    ...
]

It is an array of all the tags found via a selector

Responses

By default, when a SELECTOR is queried the entire Array<Object> of the specified selector must be sent back without the attributes. The response will look something like this:

{
    [
        {
            "tag": "img",
             "data": "",
            "attributes": {}
        }
    ]
}

Notice the empty attributes object.

Nested Selectors

Remember, Selectors can be nested. In this case, simply return the an Object with the selectors contained within the selector. The format of the response for a nested selector will be like so.

https://api/<USER_ID>/<RESOURCE_ID>/<SELECTOR_A>

Where, SELECTOR_A contains the following

SELECTOR_A: { 
    SELECTOR_A1: Array<Object>, 
    SELECTOR_A2: {
        SELECTOR_A2_1: Array<Object>
    }  
}

The response will have the format:

{ 
    SELECTOR_A1: Array<Object>, 
    SELECTOR_A2:  {
        SELECTOR_A2_1: Array<Object>
    }
}

or the type

Object<SUB_SELECTOR_KEY, Array<Object> | self>

Notice the circular nature of this type. This means a SELECTOR can have arbitrary levels of nesting,
in production we will limit the nesting to < 32 levels as it is the limit for Firebase Realtime Database.

With Attributes

Specific attributes may be requested via query parameters like so.

https://api/UserA/faraz/img_profilePic?attrs=KEY_1,KEY_2,...,KEY_N

The response must be in this format.

{
    [
        {
            "tag":  <TAG_TYPE>,
            "data": <TEXT_CONTENT>,
            "attributes": {
                <KEY_1>: <KEY_1_VALUE>,
                <KEY_2>: <KEY_2_VALUE>,
                ...
                <KEY_N>: <KEY_N_VALUE>,
             }
        }
    ],
   ...
}

Notice that all objects within the Array<Object> are returned with specified keys.

Notes

  • If any part of the URL does not exist, simply return an Error(). We will replace this with a 404 in the server later.
  • When a RESOURCE_ID is queried, return an in the format: Object<SELECTOR, Array<Object>>
  • Create a new file called Resolutions.ts, write and export your function from there.
  • Run it with Node for now and let the response simply be the return value of the function. We will make it a proper Router leter.

To-do

  • Basic query resolution
  • Nested selector query resolution
  • Basic query resolution with Attribute
  • Nested selector query resolution with Attribute

Let me know if you need help.

@FarazzShaikh FarazzShaikh added no-firebase Does not require Firebase to-do labels Jun 25, 2021
@FarazzShaikh FarazzShaikh added this to the Release 1.0 milestone Jun 25, 2021
@FarazzShaikh FarazzShaikh changed the title Route REST URL to parsed data [Core] Route REST URL to parsed data Jun 25, 2021
@Akilan1999
Copy link
Member

Alright great ! will get working on it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-firebase Does not require Firebase to-do
Projects
None yet
Development

No branches or pull requests

2 participants