All Projects → burakdede → Hoodie

burakdede / Hoodie

Licence: apache-2.0
Hoodie is a type safe wrapper around jersey http client

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Hoodie

restler
Restler is a beautiful and powerful Android app for quickly testing REST API anywhere and anytime.
Stars: ✭ 120 (+445.45%)
Mutual labels:  http-client, rest-client
Taviloglu.Wrike.ApiClient
.NET Client for Wrike API
Stars: ✭ 24 (+9.09%)
Mutual labels:  http-client, rest-client
Rx.Http
A reactive way to make HTTP Request in .NET Core 🚀
Stars: ✭ 62 (+181.82%)
Mutual labels:  http-client, rest-client
Proxy
The type-safe REST library for .NET Standard 2.0 (NetCoreStack Flying Proxy)
Stars: ✭ 40 (+81.82%)
Mutual labels:  http-client, rest-client
Restc Cpp
Modern C++ REST Client library
Stars: ✭ 371 (+1586.36%)
Mutual labels:  rest-client, http-client
NClient
💫 NClient is an automatic type-safe .Net HTTP client that allows you to call web service API methods using annotated interfaces or controllers without boilerplate code.
Stars: ✭ 25 (+13.64%)
Mutual labels:  http-client, rest-client
RESTEasy
REST API calls made easier
Stars: ✭ 12 (-45.45%)
Mutual labels:  http-client, rest-client
Fshttp
A lightweight F# HTTP library.
Stars: ✭ 181 (+722.73%)
Mutual labels:  rest-client, http-client
Requester
Powerful, modern HTTP/REST client built on top of the Requests library
Stars: ✭ 273 (+1140.91%)
Mutual labels:  rest-client, http-client
Vscode Restclient
REST Client Extension for Visual Studio Code
Stars: ✭ 3,289 (+14850%)
Mutual labels:  rest-client, http-client
unity-simple-http
A dead simple HTTP client for Unity3D
Stars: ✭ 32 (+45.45%)
Mutual labels:  http-client, rest-client
Resty
Simple HTTP and REST client library for Go
Stars: ✭ 5,368 (+24300%)
Mutual labels:  rest-client, http-client
Rump
REST client for Java that allows for easy configuration and default values. Allows for quick request construction and a huge range of modifications by using response/request interceptors, adjusting default values related to HTTP requests and creating custom instances for when you need multiple API connection setups.
Stars: ✭ 55 (+150%)
Mutual labels:  http-client, rest-client
restofus
Restofus - a cross-platform (REST) API client.
Stars: ✭ 18 (-18.18%)
Mutual labels:  http-client, rest-client
Rester
A REST client for almost any web service (Firefox and Chrome Extension)
Stars: ✭ 192 (+772.73%)
Mutual labels:  rest-client, http-client
csharp-http-client
Twilio SendGrid's C# HTTP Client for calling APIs
Stars: ✭ 25 (+13.64%)
Mutual labels:  http-client, rest-client
Python Simple Rest Client
Simple REST client for python 3.6+
Stars: ✭ 143 (+550%)
Mutual labels:  rest-client, http-client
Crest
HTTP and REST client for Crystal
Stars: ✭ 174 (+690.91%)
Mutual labels:  rest-client, http-client
roast.vim
An HTTP client for Vim, that can also be used as a REST client.
Stars: ✭ 78 (+254.55%)
Mutual labels:  http-client, rest-client
Vial Http
Simple http rest tool for vim
Stars: ✭ 412 (+1772.73%)
Mutual labels:  rest-client, http-client

Hoodie - Type safe wrapper for jersey client

Hoodie is a wrapper around the Jersey Client that makes your rest call definitions annotation based and type safe

Hoodie comes handy when you have different services and you share a lot of domain classes (which happens a lot for my case) and do not want to write same http call, auth, parsing and other stuff every time. I included some samples in test folder for api's like Spotify.

Quick Intro

1 - Define your api calls

Define Api Calls

2 - Register your interface

Register Interface

3 - Make api calls

Make api calls

# Documentation

Setting up

If its simple http request with no complicated return types you can always use String

public interface Google {

    @Request("GET /")
    String gethomePage();
}

Before calling http method you need to register class

Google google = Hoodie.registerNewTarget(Google.class, "http://www.google.com.tr");
String homepage = google.gethomePage();

Yes, its not that impressive. It comes handy when you have shared domain classes, especially between your microservices. Lets take more complicated example with Spotify API.

public interface Spotify {

    @Request("GET /v1/artists/{id} ")
    SpotifyArtist getArtist(@PathParam("id") String id);


    @Request("HEAD /v1/artists/{id} ")
    Response getArtistHeadReq(@PathParam("id") String id);


    @Request("GET /v1/artists/{id}/albums")
    SpotifyArtistAlbums getArtistAlbums(@PathParam("id") String id);


    @Request("DELETE /v1/artists/{id}/albums")
    SpotifyArtistAlbums deleteArtistAlbum(@PathParam("id") String id);


    @Header("Authorization: Bearer BQDrGfA3Urfnqn3o7V-pbJn7qOB4A5LaxwzHWbKX9SHwrYaRTSWM1W6qByQ2Z3Gpq_-0vWacIch276yFZrMQamX-pUA7jnrromnvF0jl6i1Vd-QXGx8eaxJ9frZU0VCjpBvXET5YMFDL0OugHL_7S-emoDKPJQ")
    @Request("POST /v1/users/114895047/playlists")
    Playlist createNewPlaylist(@Body PlaylistRequest playlistRequest);


    @Request("GET /v1/search")
    SpotifySearchArtists searchTrack(@QueryParam("q") String songName,
                                     @QueryParam("type") String type);
}

@Request

Your first job is to use @Request annotation with signature

@Request("HTTP_METHOD RELATIVE_PATH)

@Request("GET /v1/search")

@Header

If you have additional header along with your request just give them with @Header annotation

@Header("KEY: VALUE")

@Header("Authorization: Bearer BQDrGfA3Urfnqn3o7V-pbJn7qOB4A5LaxwzHWbKX9SHw")

@PathParam

If your path need additional path parameter like id, query string etc. put them in relative path with curly brackets and give values as method parameter wth @PathParam annotation.

@Request(HTTP_METHOD /relative/path/{path_param})

@Request("GET /v1/artists/{id} ")
getArtist(@PathParam("id") String id);

@QueryParam

If you want to send your parameters along with your url use @QueryParam as parameter within method signature. All your query parameters will be added to end of url encoded.

@QueryParam("PARAM_NAME") TYPE VAR_NAME

SpotifySearchArtists searchTrack(@QueryParam("q") String songName,
                                         @QueryParam("type") String type);

@Body

You may want to send complicated object with request body so use @Body.

RETURN_TYPE METHOD_NAME(@Body Object name)

Playlist createNewPlaylist(@Body PlaylistRequest playlistRequest);
spotify.createNewPlaylist(new PlaylistRequest());

Check other examples at test folder.

Whats New

  • ability to configure jersey client via hoodie
  • change package related problem

Download

You may need to add bintray repo

<repositories>
    <repository>
        <id>bintray</id>
        <url>https://dl.bintray.com/burakdd/maven/</url>
    </repository>
</repositories>

Get it with maven

<dependency>
    <groupId>com.burakdede</groupId>
    <artifactId>hoodie</artifactId>
    <version>0.0.3</version>
</dependency>

# License Copyright (C) Burak Dede.

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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].