All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.palantir.dialogue.annotations.Request Maven / Gradle / Ivy

There is a newer version: 4.7.0
Show newest version
/*
 * (c) Copyright 2021 Palantir Technologies Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.palantir.dialogue.annotations;

import com.palantir.dialogue.Deserializer;
import com.palantir.dialogue.HttpMethod;
import com.palantir.dialogue.Serializer;
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;

/**
 * Annotates an RPC endpoint.
 *
 * This annotation provides namespace for annotations for dialogue client generation.
 */
@Documented
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.METHOD)
public @interface Request {
    HttpMethod method();

    /**
     * Request path.
     *
     * Follows conjure format. Path parameter names must correspond to parameters on the annotated method.
     *
     * @see
     * Path string
     */
    String path();

    /**
     * Response body {@link Deserializer}. By default this deserializer is only used for successful
     * (i.e. {@code 200 <= response.code() < 300}) responses.
     *
     * @return class that implements a zero-arg constructor to be used to deserialize the response
     */
    Class accept() default Json.class;

    /**
     * Error handling strategy.
     *
     * @return class that implements a zero-arg constructor to be used to deserialize an error response
     */
    Class errorDecoder() default ConjureErrorDecoder.class;

    @Retention(RetentionPolicy.SOURCE)
    @Target(ElementType.PARAMETER)
    @interface Body {

        /**
         * Custom body {@link Serializer}.
         *
         * @return class that implements a zero-arg constructor to be used to serialize the body. Defaults to
         * {@link Json}
         */
        Class value() default Json.class;
    }

    @Retention(RetentionPolicy.SOURCE)
    @Target(ElementType.PARAMETER)
    @interface Header {
        String value();

        Class> encoder() default DefaultListParamEncoder.class;
    }

    @Retention(RetentionPolicy.SOURCE)
    @Target(ElementType.PARAMETER)
    @interface HeaderMap {
        Class> encoder() default DefaultMultimapParamEncoder.class;
    }

    @Retention(RetentionPolicy.SOURCE)
    @Target(ElementType.PARAMETER)
    @interface PathParam {
        Class> encoder() default DefaultParamEncoder.class;

        Class> listEncoder() default DefaultListParamEncoder.class;
    }

    @Retention(RetentionPolicy.SOURCE)
    @Target(ElementType.PARAMETER)
    @interface QueryParam {
        String value();

        Class> encoder() default DefaultListParamEncoder.class;
    }

    /**
     * Similar to the Feign QueryMap serialization type. Only supports simple string -> string maps.
     */
    @Retention(RetentionPolicy.SOURCE)
    @Target(ElementType.PARAMETER)
    @interface QueryMap {
        Class> encoder() default DefaultMultimapParamEncoder.class;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy