/*
 * Copyright 2017-2020 original authors
 *
 * 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
 *
 * https://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 io.micronaut.http.hateoas;

import io.micronaut.http.MediaType;

import edu.umd.cs.findbugs.annotations.Nullable;
import java.net.URI;
import java.util.Optional;

Interface for a hateoas link.

See https://tools.ietf.org/html/draft-kelly-json-hal-08#section-5

Author:Graeme Rocher
Since:1.1
/** * <p>Interface for a hateoas link.</p> * <p> * <p>See https://tools.ietf.org/html/draft-kelly-json-hal-08#section-5</p> * * @author Graeme Rocher * @since 1.1 */
public interface Link {
Help link.
/** * Help link. */
CharSequence HELP = "help";
Self link.
/** * Self link. */
CharSequence SELF = "self";
About link.
/** * About link. */
CharSequence ABOUT = "about";
Href link.
/** * Href link. */
CharSequence HREF = "href";
Returns:The URI to template to
/** * @return The URI to template to */
String getHref();
Returns:Whether the URI is templated
/** * @return Whether the URI is templated */
default boolean isTemplated() { return false; }
Returns:The type of the URI
/** * @return The type of the URI */
default Optional<MediaType> getType() { return Optional.empty(); }
Returns:The deprecation URI
/** * @return The deprecation URI */
default Optional<String> getDeprecation() { return Optional.empty(); }
Returns:The profile URI
/** * @return The profile URI */
default Optional<String> getProfile() { return Optional.empty(); }
Returns:The name of the link
/** * @return The name of the link */
default Optional<String> getName() { return Optional.empty(); }
Returns:The title of the link
/** * @return The title of the link */
default Optional<String> getTitle() { return Optional.empty(); }
Returns:The language of the link
/** * @return The language of the link */
default Optional<String> getHreflang() { return Optional.empty(); }
Create a link from the given URI.
Params:
  • uri – The URI
Returns:The link
/** * Create a link from the given URI. * * @param uri The URI * @return The link */
static Link of(URI uri) { return new DefaultLink(uri.toString()); }
Create a link from the given URI.
Params:
  • uri – The URI
Returns:The link
/** * Create a link from the given URI. * * @param uri The URI * @return The link */
static Link of(String uri) { return new DefaultLink(uri); }
Create a link from the given URI.
Params:
  • uri – The URI
Returns:The link
/** * Create a link from the given URI. * * @param uri The URI * @return The link */
static Link.Builder build(URI uri) { return new DefaultLink(uri.toString()); }
Create a link from the given URI.
Params:
  • uri – The URI
Returns:The link
/** * Create a link from the given URI. * * @param uri The URI * @return The link */
static Link.Builder build(String uri) { return new DefaultLink(uri); }
Build for creating Link instances.
/** * Build for creating {@link Link} instances. */
interface Builder {
Params:
  • templated – Whether the URI is templated
See Also:
Returns:The builder
/** * @param templated Whether the URI is templated * @return The builder * @see Link#isTemplated() */
Builder templated(boolean templated);
Params:
  • profile – The profile URI
See Also:
Returns:The builder
/** * @param profile The profile URI * @return The builder * @see Link#getProfile() */
Builder profile(@Nullable URI profile);
Params:
  • profileURI – The profile URI
See Also:
Returns:The builder
/** * @param profileURI The profile URI * @return The builder * @see Link#getProfile() */
Builder profile(@Nullable String profileURI);
Params:
  • deprecation – The deprecation URI
See Also:
Returns:The builder
/** * @param deprecation The deprecation URI * @return The builder * @see Link#getDeprecation() */
Builder deprecation(@Nullable URI deprecation);
Params:
  • deprecationURI – The deprecation URI
See Also:
Returns:The builder
/** * @param deprecationURI The deprecation URI * @return The builder * @see Link#getDeprecation() */
Builder deprecation(@Nullable String deprecationURI);
Params:
  • title – The title of the link
See Also:
Returns:The builder
/** * @param title The title of the link * @return The builder * @see Link#getTitle() */
Builder title(@Nullable String title);
Params:
  • name – The name of the link
See Also:
Returns:The builder
/** * @param name The name of the link * @return The builder * @see Link#getName() */
Builder name(@Nullable String name);
Params:
  • hreflang – The language of the link
See Also:
Returns:The builder
/** * @param hreflang The language of the link * @return The builder * @see Link#getHreflang() */
Builder hreflang(@Nullable String hreflang);
Params:
  • mediaType – The type of the URI
See Also:
Returns:The builder
/** * @param mediaType The type of the URI * @return The builder * @see Link#getType() */
Builder type(@Nullable MediaType mediaType);
Build the link.
Returns:The Link
/** * Build the link. * * @return The {@link Link} */
Link build(); } }