Skip to content

Merge with Plack::Middleware::RestAPI #7

@nichtich

Description

@nichtich

I wonder what Plack::Middleware::RestAPI can do above Plack::Middleware::REST. We should merge both modules to not confuse possible users which module to use. In my personal opinion it is not good to modify the PSGI $env but we could add a possibility to configure Plack::Middleware::REST with an object:

...
enable 'REST',
    resource => My::API::Resource->new,
    collection => My::API::Collection->new,
...

package My::API::Resource;
sub GET { ... }   # get
sub HEAD { ... } # get
sub POST { ... } # 

package My::API::Collection;
sub DELETE { ... } # delete resource
sub POST { ... }     # create resource
sub GET { ... }       # list resources

However, I'd prefer not naming the methods with HTTP methods so one use the same object as resource and collection:

package My::API;
sub get { ... }   # GET and HEAD on resources
sub upsert { ... } # PUT on a resource
sub patch { ... } # PATCH on resource
sub delete { ... } # DELETE on resource
sub list { ... }   # GET on collection
sub create { ... } # POST on collection

...
enable 'REST', via => My::API->new;

In the end the latter could also be done the other way round:

package My::API;
use parent 'Plack::Middleware::REST'; # or Plakc::App::REST
# just defined method get, upsert, delete... to support these methods

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions