How to have a @PATCH annotation for JAX-RS?

前端 未结 5 693
渐次进展
渐次进展 2021-01-30 19:51

JAX-RS has annotations for HTTP verbs such as GET (@GET) and POST (@POST) but there is no @PATCH annotation. How

5条回答
  •  爱一瞬间的悲伤
    2021-01-30 20:27

    Using JAX-RS 2.1?

    JAX-RS 2.1 added @PATCH to the list of supported HTTP methods.

    Using Swagger?

    When using Swagger to document a REST API, you could use the existing @PATCH annotation defined in the io.swagger.jaxrs package.

    Using Jersey and Dropwizard?

    Dropwizard defines a @PATCH annotation in the io.dropwizard.jersey package.

    Write your own

    If the above mentioned approaches don't work for you, you can write your own @PATCH annotation:

    @Target({ElementType.METHOD})
    @Retention(RetentionPolicy.RUNTIME)
    @HttpMethod("PATCH")
    public @interface PATCH { }
    

    The @HttpMethod annotation is used to associate the name of a HTTP method with an annotation, creating a what the JAX-RS specification calls resource method designator.

    Your own @PATCH annotation should work fine in Swagger.

提交回复
热议问题