personium / personium-core

Core module of Personium
https://personium.io
Apache License 2.0
88 stars 16 forks source link

RegEx path support in Engine Service Collection config #338

Closed shimono closed 3 years ago

shimono commented 5 years ago

Overview

Make Engine Service Collection path configuration accept RegEx instead of fixed path string. This makes more flexible engine service endpoint possible.

Problem to solve.

One of the typical use cases of engine service is to create a restricted view to an odata entity set. However you can't create an odata-compatible endpoint out of engine since a custom endpoint created by an engine service only serves at a fixed url.

Solution

Extending current Engine Service Collection configuration syntax a bit and accept RegEx or some simple pattern like the followings.

current

          <p:service language="JavaScript">
            <p:path name="path1" src="script1.js"/>
            <p:path name="path2" src="script2.js"/>
          </p:service>

extended

          <p:service language="JavaScript">
            <p:path name="view1" src="entities.js"/>
            <p:path regEx="view1\((.+)\)" src="entity.js"/>
          </p:service>
dixonsiu commented 3 years ago

Add requirements from CEPS 2.0 Draft.

shimono commented 3 years ago

What about the following for new syntax.

<p:route path="{express syntax}" script="entity.js" />

yoh1496 commented 3 years ago

I googled some example of URI templating. I realized that there are mainly two pattern, RFC 6570 style and express-style.

Result of search

Spring boot

https://docs.spring.io/spring-framework/docs/3.2.x/spring-framework-reference/html/mvc.html#mvc-ann-requestmapping-uri-templates using URI Templating defined in RFC 6570. (maybe, using JAX-RS internally)

RouterFunction<ServerResponse> route = route()
    .GET("/person/{id}", accept(APPLICATION_JSON), handler::getPerson)
    .GET("/person", accept(APPLICATION_JSON), handler::listPeople)
    .POST("/person", handler::createPerson)
    .build();

Ruby on Rails

https://guides.rubyonrails.org/routing.html

I cannot find any documentation containing details of templating. (please tell me if you know)

get 'photos/:id/with_user/:user_id', to: 'photos#show'

Express

https://expressjs.com/ja/guide/routing.html

internally using path-to-regexp package https://github.com/pillarjs/path-to-regexp/tree/v1.7.0

app.get('/users/:userId/books/:bookId', function (req, res) {
  res.send(req.params)
})

Vue router

https://router.vuejs.org/ja/guide/essentials/dynamic-matching.html using express-style path expression (path-to-regexp)

React router

https://reactrouter.com/web/api/Route/path-string-string using express-style path expression (path-to-regexp)

Laravel

https://laravel.com/docs/8.x/routing

example

public function boot()
{
    Route::pattern('id', '[0-9]+');

    parent::boot();
}

Route::get('user/{id}/profile', function ($id) {
    //
})->name('profile');

$url = route('profile', ['id' => 1]);

ASP.NET Core

https://docs.microsoft.com/en-us/aspnet/core/fundamentals/routing?view=aspnetcore-3.1#route-constraint-reference

example

[Route("users/{id:int:min(1)}")]