= RestfulClient
:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you 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.

Setup the Restful Client with Basic-Auth:Make a Request and then digest the Response:

For example:

----

val clientConfig = RestfulClientConfig.builder();
    .restfulBaseUrl("http://localhost:8080/helloworld/restful/")
        .authenticationMode(AuthenticationMode.BASIC)
        .basicAuthUser("sven")
        .basicAuthPassword("pass")
.useRequestDebugLogging(true) // default = false
.build();

RestfulClient client = RestfulClient.ofConfig(clientConfig);
----

----
 _Builder request = client.request("services/myService/actions/lookupMyObjectById/invoke")
    .accept(RestfulClientMediaType.SIMPLE_JSON.mediaTypeFor(MyObject.class, EnumSet.of(SuppressionType.RO)));

Entity args = client.arguments()
        .addActionParameter("id", "12345")
        .build();

Response response = request.post(args);

Try digest = client.digest(response, MyObject.class);_ 

if(digest.isSuccess()) {
    System.out.println("result: "+ digest.getValue().orElseThrow().get$$instanceId());
} else {
    digest.getFailure().get().printStackTrace();
}
----

== API

[source,java]
.RestfulClient.java
----
class RestfulClient {
  RestfulClient ofConfig(RestfulClientConfig clientConfig)     // <.>
  RestfulClient ofConfig(RestfulClientConfig clientConfig, AuthorizationHeaderFactory authorizationHeaderFactory)     // <.>
  RestfulClient ofConfig(RestfulClientConfig clientConfig, UnaryOperator<ClientBuilder> configRefiner)
  RestfulClient ofConfig(RestfulClientConfig clientConfig, UnaryOperator<ClientBuilder> configRefiner, AuthorizationHeaderFactory authorizationHeaderFactory)
  RestfulClientConfig getConfig()
  Client getJaxRsClient()
  void close()
  Builder request(String path)
  ActionParameterListBuilder arguments()
  Try<T> digest(Response response, Class<T> entityType)
  Try<Can<T>> digestList(Response response, Class<T> entityType, GenericType<List<T>> genericType)
  Try<T> digestValue(Response response, ValueSemanticsProvider<T> valSemantics)     // <.>
  URI uri(String path)     // <.>
}
----

<.> xref:#ofConfig_RestfulClientConfig[ofConfig(RestfulClientConfig)]
<.> xref:#ofConfig_RestfulClientConfig_AuthorizationHeaderFactory[ofConfig(RestfulClientConfig, AuthorizationHeaderFactory)]
<.> xref:#digestValue_Response_ValueSemanticsProvider[digestValue(Response, ValueSemanticsProvider)]
+
--
For transport of _ValueDecomposition_ over REST.
--
<.> xref:#uri_String[uri(String)]
+
--
Returns an _URI_ constructed from this client's base path plus given relative _path_ .
--

== Members

[#ofConfig_RestfulClientConfig]
=== ofConfig(RestfulClientConfig)

[#ofConfig_RestfulClientConfig_AuthorizationHeaderFactory]
=== ofConfig(RestfulClientConfig, AuthorizationHeaderFactory)

[#digestValue_Response_ValueSemanticsProvider]
=== digestValue(Response, ValueSemanticsProvider)

For transport of _ValueDecomposition_ over REST.

[#uri_String]
=== uri(String)

Returns an _URI_ constructed from this client's base path plus given relative _path_ .
