Adding custom HTTP methods

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Adding custom HTTP methods

Paul C. Bryan
It seems that if I want to add handling of any custom HTTP methods, I will need to perform some brain surgery by accessing objects in org.restlet.engine. Am I right, or have  I missed something obvious?

Paul
Reply | Threaded
Open this post in threaded view
|

Re: Adding custom HTTP methods

mqm85
Hello, I posted a similar thing here:
http://restlet.tigris.org/issues/show_bug.cgi?id=1270

I said:

"I'd like to ask a new capability in the engine and api in order
to natively support custom http verbs or methods to extend the original get, post, put, delete,
etc.. . I think it would make more confortable the framework for real
applications that need this feature.

Currently there is the Tunnel Service to set the verbs as a parameter in the url
and the Tunnel Service makes it appear as an actual http request of the
verb specified so I think it could simply not to limit the kind of verbs, now in
a ServerResource we have the nice annotations like @Get, @Post... verbs so why
couldn't we just have something like: @CustomVerb("myCustomVerb") ?

Currently it's very limiting the 4 rest verbs so there's a need to extend it and
if the engine and api support it natively would be great to improve the
possibilities and at the same time keeping the structure of the code following
the same logic as any "classic" rest verb.

I hope you add this feature sooner than later if possible.
Thanks for yout attention ;) "
Reply | Threaded
Open this post in threaded view
|

Re: Adding custom HTTP methods

Fabian Mandelbaum
If the verbs of the HTTP standard (they are more than 4 BTW, please
take a look at http://en.wikipedia.org/wiki/Http) together with the
verbs of the WebDAV HTTP extension standard (take a look at
http://en.wikipedia.org/wiki/Webdav) are not enough (they should
be...) you can always do as suggested, taking advantage of the
TunnelService to request with any verb you want, over HTTP.

You can always add your own annotations for the verbs you want, it's
very simple, here you have an example for WebDAV's PROPFIND verb
(shamesly modelled after Restlet's own @Get, etc. annotations, for
which you also have the sources available):

/*
____________________________________________________________________
Copyright 2010-2011 NeoDoc SARL

This file is part of Calenco Extensions.

   Calenco is free software: you can redistribute it and/or modify
   it under the terms of the GNU Affero General Public License as
   published by the Free Software Foundation, either version 3 of
   the License, or (at your option) any later version.

   Calenco is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU Affero General Public License for more details.

   You should have received a copy of the GNU Affero General Public
   License along with Calenco.  If not, see
   <http://www.gnu.org/licenses/>.

____________________________________________________________________
 */
package com.calenco.ext.webdav.annotation;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.restlet.engine.Method;
import org.restlet.service.MetadataService;

/**
 * Annotation for WebDAV methods that return properties for a resource. Its
 *  semantics is equivalent to an WebDAV PROPFIND method.<br/>
 * <br/>
 * Example:
 *
 * <pre>
 * &#064;Propfind
 * public Representation getProperties();
 * </pre>
 *
 * @author fabman
 */
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
@Method("PROPFIND") // NOI18N
public @interface Propfind {
    /**
     * Specifies the media type of the request and response entities as
     * extensions. If only one extension is provided, the extension applies to
     * both request and response entities. If two extensions are provided,
     * separated by a comma, then the first one is for the request entity and
     * the second one for the response entity.<br/>
     * <br/>
     * If several media types are supported, their extension can be specified
     * separated by "|" characters. Note that this isn't the full MIME type
     * value, just the extension name declared in {@link MetadataService}. For a
     * list of all predefined extensions, please check
     * {@link MetadataService#addCommonExtensions()}. New extension can be
     * registered using
     * {@link MetadataService#addExtension(String, org.restlet.data.Metadata)}
     * method.
     *
     * @return <code>xml</code> since all WebDAV request and response entities
     * must be XML.
     */
    String value() default "xml"; // NOI18N

}


Good luck!

On Sat, May 21, 2011 at 12:42 PM, Mario Quesada <[hidden email]> wrote:

> Hello, I posted a similar thing here:
> http://restlet.tigris.org/issues/show_bug.cgi?id=1270
>
> I said:
>
> "I'd like to ask a new capability in the engine and api in order
> to natively support custom http verbs or methods to extend the original get,
> post, put, delete,
> etc.. . I think it would make more confortable the framework for real
> applications that need this feature.
>
> Currently there is the Tunnel Service to set the verbs as a parameter in the
> url
> and the Tunnel Service makes it appear as an actual http request of the
> verb specified so I think it could simply not to limit the kind of verbs,
> now in
> a ServerResource we have the nice annotations like @Get, @Post... verbs so
> why
> couldn't we just have something like: @CustomVerb("myCustomVerb") ?
>
> Currently it's very limiting the 4 rest verbs so there's a need to extend it
> and
> if the engine and api support it natively would be great to improve the
> possibilities and at the same time keeping the structure of the code
> following
> the same logic as any "classic" rest verb.
>
> I hope you add this feature sooner than later if possible.
> Thanks for yout attention ;) "
>
>
> --
> View this message in context: http://restlet-discuss.1400322.n2.nabble.com/Adding-custom-HTTP-methods-tp6317815p6389660.html
> Sent from the Restlet Discuss mailing list archive at Nabble.com.
>
> ------------------------------------------------------
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2743360
>



--
Fabián Mandelbaum
IS Engineer

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2745034
Reply | Threaded
Open this post in threaded view
|

Re: Adding custom HTTP methods

mqm85
Cool, that's what I needed,