Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Parse URL path according to the OData specification too #12

Open
prantlf opened this issue Dec 28, 2014 · 2 comments
Open

Parse URL path according to the OData specification too #12

prantlf opened this issue Dec 28, 2014 · 2 comments

Comments

@prantlf
Copy link
Contributor

prantlf commented Dec 28, 2014

Breaking the path into resources and predicates would be helpful too when processing the OData URL, because hre can be expressions inside the path. For example, /Customers(123)/ContactName could be parsed into a JSON object with a schema similar to the query parsing output:

[
  {
    "name": "Customers",
    "predicates": [
      {
        "type": "literal",
        "value": 123
      }
    ]
  },
  {
    "name": "ContactName"
  }
]

Another example for /Orders(CustomerID=123,Pending=true) could be:

[
  {
    "name": "Orders",
    "predicates": [
      {
        "type": "property",
        "name": "CustomerID",
        "value": 123
      },
      {
        "type": "property",
        "name": "Pending",
        "value": true
      }
    ]
  }
]

There could be either a separate parsing function for the path, or the current odata-parser module could support both; the path with an optional query or the query alone.

I tried the former in the parse-path-separate branch with the extended interface in lib/index.js:

module.exports = {
  parse: require('./odata-parser').parse,
  parsePath: require('./odata-path-parser').parse
};

I could not find a real advantage of having handling the two URL parts separated. A disadvantage was duplicating a big part of the PEG grammar in the URL path handling file. Parsing can handle all three possibilities (path, path + query, query) with a simpler interface (just a single parse method) and the only challenge is how to return the path without breaking the current interface. I tried adding a new key - $path - to the output map in the parse-path-integrated branch; it is not a reserved OData field and the parse method has a common result schema:

{
  "$path": [
    // array of resources from the first and second samples above
  ],
  "$select": [
    "Name"
  ],
  ...
}

What do you think? Thanks!

@jfromaniello
Copy link
Member

Yes, it seems a very good idea.

@htammen
Copy link

htammen commented Nov 9, 2015

Hi,
as far as I see this has not been implemented yet. Am I right?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants