https://github.com/luanpotter/http-facade
My take on a simple HTTP Façade for easy request making.
https://github.com/luanpotter/http-facade
http-client java simple
Last synced: about 1 year ago
JSON representation
My take on a simple HTTP Façade for easy request making.
- Host: GitHub
- URL: https://github.com/luanpotter/http-facade
- Owner: luanpotter
- License: mit
- Created: 2017-04-08T18:48:59.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2021-02-16T20:34:09.000Z (over 5 years ago)
- Last Synced: 2025-04-23T19:25:41.002Z (about 1 year ago)
- Topics: http-client, java, simple
- Language: Java
- Homepage:
- Size: 375 KB
- Stars: 4
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# http-facade
[](https://maven-badges.herokuapp.com/maven-central/xyz.luan/http-facade)
[](https://github.com/luanpotter/http-facade/releases)
[](https://opensource.org/licenses/MIT)
My take on a simple HTTP Façade for easy request making.
Zero-dependency, unobtrusive, Java 7/Google App Engine-ready API for some pretty HTTP handling.
## Maven
```xml
xyz.luan
http-facade
2.5.1
```
## Examples
Simple get:
```java
Response r = new HttpFacade("www.google.com").get();
r.status() // 200
r.content() // ...
```
More complex request:
```java
new HttpFacade("luan.xyz/api/people")
.header("key", "value")
.body("{ id: 42, name: \"Luan\" }")
.post();
```
Parse URL's, set form and query params, handle cookies, authentication (built-in non-platform-dependent Base64 enc/dec), and more.
For problems with SSL requests and Java outdated CA certificate repositories, see [here](doc/SSL.md).
## Mocking Requests
If you want to mock a request in order to always retrieve a specific response, instead of actually making the request, you can use MockedHttpFacade and MockedResponse.
Simply inject/instantiate a mocked service to do the request; see the following example:
```java
class MyService {
public void sendRequest(String url) {
getFacade(url).get();
}
public HttpFacade getFacade(String url) {
return new HttpFacade(url);
}
}
class MockMyService extends MyService {
@Override
public HttpFacade getFacade(String url) {
MockedResponse.build().withStatus(200).withContent("{ name : mock }");
return new MockedHttpFacade(url).mockResponse(mock);
}
}
```