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

Provide tooling for working with URI Templates #4

Open
tpluscode opened this issue Nov 28, 2016 · 0 comments
Open

Provide tooling for working with URI Templates #4

tpluscode opened this issue Nov 28, 2016 · 0 comments

Comments

@tpluscode
Copy link
Contributor

tpluscode commented Nov 28, 2016

Currently there is no concrete way to simplify how URI Templates are used throughout a Hydra application.

First, they are used as create resource identifiers for serialized objects. Currently the only way is to manually use a URI Template to construct the identifier

public class MyModel 
{
    public Uri Id { get; set; }
}

var model = new MyModel();
var template = new UriTemplate("path/{name}{?includeSub}");
model.Id = template.BindByName(new Dictionary<string, object>
{
    { "name", "guid" },
    { "includeSub", true }
});

Second, the very same template could be used for routing in Nancy. It is what I started implementing in Nancy.Routing.UriTemplates

public class MyModelModule : UriTemplateModule 
{
    public MyModelModule()
    {
        using (Templates)
        {
            Get("path/{name}{?includeSub}", _ => new MyModel());
        }
    }
}

By introducing a pattern similar to ServiceStack routing, where routing is part of the model it should be possible to simplify handling of URI Templates for routing and creating identifiers.

Something like

[IdentifierTemplate("path/{name}{?includeSub}")]
public class MyModel 
{
    public Uri Id { get; set; }

    public string Name { get; set; }
}

var model = new MyModel { Name = "Tomasz" };
model.Id = model.BindTemplate(new { includeSub = true });

The BindTemplate would be an extension which looks for IdentifierTemplateAttribute on given instance's type and uses passed params and/or property values to fill in the template.

And finally, the route path wouldn't be needed at all in module

// ArgolisModule inheriting UriTemplateModule
public class MyModelModule : ArgolisModule
{
    public MyModelModule()
    {
        using (Templates)
        {
            Get<MyModel>(_ => new MyModel());
        }
    }
}
tpluscode added a commit to wikibus/wikibus-backend that referenced this issue Nov 29, 2016
tpluscode added a commit to wikibus/wikibus-backend that referenced this issue Mar 10, 2018
* proof of concept for wikibus/Argolis#4

* move getting template from module and some comments

* make template api injectable

* replace all handling of templates with attributes

* add interfaces and make stuff actually injectable

* make action `Func<object, object>`

* add async variant to argolis module

* make repositories and actions async

* more work on templates

* update with new Argolis packages

* remove spike code

* fix tests to reflect change to template usage

* automatically deploy only on master

* fix appveyor tabs

* less changef for PR

* paket simplify

* paket update

* change routing templates

* code review and removed obsolete stuff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant