Skip to content
This repository has been archived by the owner on Feb 17, 2022. It is now read-only.

Commit

Permalink
Change to version 1.3-RC2
Browse files Browse the repository at this point in the history
- Add Quick-Start guide in readme
- set true as default value for @SkipResponseBody
- add setFoxHttpParser to ClientBuilde
- add executeNow method to RequestBuilder
- add HAL+JSON to ContentTypes
  • Loading branch information
itsmefox committed Jun 29, 2017
1 parent acbe5df commit deb0771
Show file tree
Hide file tree
Showing 7 changed files with 111 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# target folders
*/target/
/target

# Mac
.DS_Store
Expand Down
63 changes: 61 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

**FoxHttp provides a fast and easy http client for Java and Android. It's part of the GroundWork Project by Viascom.**

[![master](https://img.shields.io/badge/master-v1.2.1-brightgreen.svg)](https://github.com/Viascom/FoxHttp/tree/master)
[![develop](https://img.shields.io/badge/develop-v1.3--RC1-brightgreen.svg)](https://github.com/Viascom/FoxHttp/tree/develop)
[![master](https://img.shields.io/badge/master-v1.3--RC1-brightgreen.svg)](https://github.com/Viascom/FoxHttp/tree/master)
[![develop](https://img.shields.io/badge/develop-v1.3--RC2-brightgreen.svg)](https://github.com/Viascom/FoxHttp/tree/develop)
[![Maven Central](https://img.shields.io/maven-central/v/ch.viascom.groundwork/foxhttp.svg)]()
[![Bintray](https://img.shields.io/bintray/v/viascom/GroundWork/ch.viascom.groundwork%3Afoxhttp.svg)]()<br/>
[![Size](https://img.shields.io/badge/size-197.2_KB-brightgreen.svg)]()
Expand Down Expand Up @@ -39,3 +39,62 @@ Request against [httpbin](https://httpbin.org/) which was installed on localhost
* URL placeholder support
* _Advanced cache strategy (coming soon)_
* _GroundWork Server-Security support (coming soon)_
* _HAL support (coming soon)_

## Quick Start:

### Dependency

#### maven
```xml
<dependency>
<groupId>ch.viascom.groundwork</groupId>
<artifactId>foxhttp</artifactId>
<version>1.3-RC2</version>
</dependency>
```

#### gradle
```
compile 'ch.viascom.groundwork:foxhttp:1.3-RC2'
```

### Send a request with JSON response deserialization
To run this example you need to add Gson to your dependency management!
```java
// Define Http-Client and set parser for serialization/deserialization
FoxHttpClient foxHttpClient = new FoxHttpClientBuilder(new GsonParser()).build();

// Define a System-Out logger
foxHttpClient.setFoxHttpLogger(new SystemOutFoxHttpLogger(true, "FoxHttp-Logger"));

// Create and Execute GET Request
FoxHttpResponse response = new FoxHttpRequestBuilder("http://httpbin.org/get?search=Viascom", RequestType.GET, foxHttpClient).executeNow();

// Deserialization response
GetResponse object = repsponse.getParsedBody(GetResponse.class);

// Print result
System.out.println("Parsed-Output: " + object);
```

To deserialize the response you need the following model:
```java
public class GetResponse implements Serializable {

public HashMap<String, String> args;
public HashMap<String, String> headers;
public String origin;
public String url;

@Override
public String toString() {
return "GetResponse{" +
"args=" + args +
", headers=" + headers +
", origin='" + origin + '\'' +
", url='" + url + '\'' +
'}';
}
}
```
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</parent>

<artifactId>foxhttp</artifactId>
<version>1.3-RC1</version>
<version>1.3-RC2</version>


<name>GroundWork - FoxHttp</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import java.lang.annotation.*;

/**
* The @SkipResponseBody annotation will skip the response body if set to true. The default is false.
* The @SkipResponseBody annotation will skip the response body if set to true. If the annotation is present, the default is true.
*
* @author [email protected]
*/
@Documented
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface SkipResponseBody {
boolean value();
boolean value() default true;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import ch.viascom.groundwork.foxhttp.interceptor.response.GZipResponseInterceptor;
import ch.viascom.groundwork.foxhttp.log.FoxHttpLogger;
import ch.viascom.groundwork.foxhttp.parser.FoxHttpParser;
import ch.viascom.groundwork.foxhttp.parser.GsonParser;
import ch.viascom.groundwork.foxhttp.parser.XStreamParser;
import ch.viascom.groundwork.foxhttp.placeholder.FoxHttpPlaceholderStrategy;
import ch.viascom.groundwork.foxhttp.proxy.FoxHttpProxyStrategy;
import ch.viascom.groundwork.foxhttp.ssl.FoxHttpHostTrustStrategy;
Expand Down Expand Up @@ -112,6 +114,39 @@ public FoxHttpClientBuilder setFoxHttpRequestParser(FoxHttpParser foxHttpRequest
return this;
}

/**
* Set the request and response parser
*
* @param foxHttpParser a FoxHttpParser
*
* @return FoxHttpClientBuilder (this)
*/
public FoxHttpClientBuilder setFoxHttpParser(FoxHttpParser foxHttpParser){
setFoxHttpRequestParser(foxHttpParser);
setFoxHttpResponseParser(foxHttpParser);
return this;
}

/**
* Activate default gson parser for json
*
* @return FoxHttpClientBuilder (this)
*/
public FoxHttpClientBuilder activateGsonParser(){
setFoxHttpParser(new GsonParser());
return this;
}

/**
* Activate default xstream parser for xml
*
* @return FoxHttpClientBuilder (this)
*/
public FoxHttpClientBuilder activateXStreamParser(){
setFoxHttpParser(new XStreamParser());
return this;
}

/**
* Define a map of FoxHttpInterceptors
* <i>This will override the existing map of interceptors</i>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ch.viascom.groundwork.foxhttp.FoxHttpClient;
import ch.viascom.groundwork.foxhttp.FoxHttpRequest;
import ch.viascom.groundwork.foxhttp.FoxHttpResponse;
import ch.viascom.groundwork.foxhttp.authorization.FoxHttpAuthorization;
import ch.viascom.groundwork.foxhttp.authorization.FoxHttpAuthorizationScope;
import ch.viascom.groundwork.foxhttp.body.request.FoxHttpRequestBody;
Expand Down Expand Up @@ -384,4 +385,13 @@ public FoxHttpRequest build() throws FoxHttpRequestException {
return request;
}

/**
* Build and execute the FoxHttpRequest of this builder
*
* @return FoxHttpResponse response of the request
*/
public FoxHttpResponse executeNow() throws FoxHttpException {
return build().execute();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class ContentType {
public static final ContentType APPLICATION_ATOM_XML = create("application/atom+xml", Charset.forName(UTF8));
public static final ContentType APPLICATION_FORM_URLENCODED = create("application/x-www-form-urlencoded", Charset.forName(UTF8));
public static final ContentType APPLICATION_JSON = create("application/json", Charset.forName(UTF8));
public static final ContentType APPLICATION_HAL_JSON = create("application/hal+json", Charset.forName(UTF8));
public static final ContentType APPLICATION_OCTET_STREAM = create("application/octet-stream", (Charset) null);
public static final ContentType APPLICATION_SVG_XML = create("application/svg+xml", Charset.forName(UTF8));
public static final ContentType APPLICATION_XHTML_XML = create("application/xhtml+xml", Charset.forName(UTF8));
Expand Down

0 comments on commit deb0771

Please sign in to comment.