skyscreamer / yoga

Yoga is RESTful but flexible.
http://yoga.skyscreamer.org/
Apache License 2.0
156 stars 66 forks source link

Json aliases feature #247

Open manland opened 9 years ago

manland commented 9 years ago

This pull-request wants to simplify the definitions of aliases.

Here at ITK we use intensively aliases, with time our aliases.properties grownth exponentially. Lots of patterns are similare but with little changes.

So we have implemented a json parser, and we have added variable feature.

Specifications :

Examples (from tests) :

from

$child=test,child(value)

to

{
  "$child": [
    "test",
    {
      "child": ["value"]
    }
  ]
}

Or from

$children=test,child(value,value2),child2(value3,child3(*))

to

{
  "$children": [
    "test",
    {
      "child" : [
        "value", 
        "value2"
      ]
    },
    {
      "child2": [
        "value3", 
        {
          "child3": ["*"]
        }
      ]
    }
  ]
}

And with variables :

{
  "@variable": [
    "test", 
    "test2"
  ],
  "$variable": [
    "testvar",
    {
      "childvar": [
        "child",
        "@variable"
      ]
    }
  ]
}

Could be represented as :

$variable=testvar,childvar(child,test,test2)

More complex variables can be used.

The JSON files must be in yoga_aliases directory in the ressources directory.

It can contain all files you want, the name of file is not used, but it needs to finish by .json.

We use a file, for a view in our application, and each file contains all requests aliases for this view.

A variable can be defined in one file and used in an other one. And a file can contain only aliases or only variables, it's as you want.

To resume :

eric-taix commented 9 years ago

+1 Great addition

kentongray commented 9 years ago

very interesting, hoping to see some life in this project!

julien-lafont commented 9 years ago

+1, very interesting feature!