All Projects → AviranAbady → woodpecker

AviranAbady / woodpecker

Licence: Apache-2.0 license
woodpecker http client for Android

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to woodpecker

Easygo
基于Kotlin、OkHttp的声明式网络框架,像写HTML界面一样写网络调用代码
Stars: ✭ 40 (+135.29%)
Mutual labels:  chain, http-client
rmfr
Node.js implementation of rm -fr – recursive removal of files and directories
Stars: ✭ 23 (+35.29%)
Mutual labels:  promise, delete
wumpfetch
🚀🔗 A modern, lightweight, fast and easy to use Node.js HTTP client
Stars: ✭ 20 (+17.65%)
Mutual labels:  post, get
Fetch
Asynchronous HTTP client with promises.
Stars: ✭ 29 (+70.59%)
Mutual labels:  promise, http-client
Metasync
Asynchronous Programming Library for JavaScript & Node.js
Stars: ✭ 164 (+864.71%)
Mutual labels:  promise, chain
lightflow
A tiny Promise-inspired control flow library for browser and Node.js.
Stars: ✭ 29 (+70.59%)
Mutual labels:  promise, chain
do
Simplest way to manage asynchronicity
Stars: ✭ 33 (+94.12%)
Mutual labels:  promise, chain
Ppipe
pipes values through functions, an alternative to using the proposed pipe operator ( |> ) for ES
Stars: ✭ 192 (+1029.41%)
Mutual labels:  promise, chain
Create Request
Apply interceptors to `fetch` and create a custom request function.
Stars: ✭ 34 (+100%)
Mutual labels:  promise, http-client
Node Fetch
A light-weight module that brings the Fetch API to Node.js
Stars: ✭ 7,176 (+42111.76%)
Mutual labels:  promise, http-client
Wretch
A tiny wrapper built around fetch with an intuitive syntax. 🍬
Stars: ✭ 2,285 (+13341.18%)
Mutual labels:  promise, http-client
Axios
Promise based HTTP client for the browser and node.js
Stars: ✭ 89,857 (+528470.59%)
Mutual labels:  promise, http-client
SierraChartZorroPlugin
A Zorro broker API plugin for Sierra Chart, written in Win32 C++.
Stars: ✭ 22 (+29.41%)
Mutual labels:  put
typescript-lazy-get-decorator
Lazily evaluates a getter on an object and caches the returned value
Stars: ✭ 33 (+94.12%)
Mutual labels:  get
try-to-catch
functional try-catch wrapper for promises
Stars: ✭ 30 (+76.47%)
Mutual labels:  promise
oh-my-request
🔮 simple request library by java8
Stars: ✭ 41 (+141.18%)
Mutual labels:  http-client
Redux
No description or website provided.
Stars: ✭ 40 (+135.29%)
Mutual labels:  promise
httper
An asynchronous HTTP(S) client built on top of hyper.
Stars: ✭ 16 (-5.88%)
Mutual labels:  http-client
crud-app
❄️ A simple and beautiful CRUD application built with React.
Stars: ✭ 61 (+258.82%)
Mutual labels:  delete
zkits-requester
Zero dependency HTTP client.
Stars: ✭ 13 (-23.53%)
Mutual labels:  http-client

woodpecker

Lean HTTP client for Android.
Aiming to provide simplicity, minimal setup, chain requests without nesting code blocks.
GET, POST, PUT, HEAD requests are supported.
Upstream/Downstream progress listeners are available for upload/download progress tracking.

See it in action, Android demo project.

Integrate

compile 'org.aviran.woodpecker:woodpecker:0.9.1'

Over the top proof of concept

The following scenario fires 6 http requests in a row, passing data from one to the other when necessary.
Quick initialization, build the request chain without nesting them inside each other's response callbacks.

// Initialize Woodpecker
Woodpecker.initialize(new WoodpeckerSettings("http://woodpecker.aviran.org"));

// Run the following 6 requests, consecutively, passing data from one to the other.

// POST  login    /login - post body: username=user&password=password
// GET   list     /list?page=1&pageSize=10
// GET   item     /item/{id}
// POST  review   /review - post body: { name: Aviran, review: This is awesome }
// GET   get      /image.png - download binary file
// PUT   upload   /upload - upload binary image file

Woodpecker
  .begin()  // POST /login
  .request(new LoginRequest("username", "p@ssw0rd"))
  .then(new WoodpeckerResponse<LoginResponse>() {
      @Override
      public void onSuccess(LoginResponse response) {
          // Update authentication token for the follwing requests
          Woodpecker.getSettings().addHeader("token", response.getToken());
      }
  })       // GET /list?page=1&pageSize=10
  .request(new ListRequest(1, 10))
  .then(new WoodpeckerResponse<List<ItemResponse>>() {
      @Override
      public void onSuccess(List<ItemResponse> response) {
          // Get next request object
          ItemRequest itemRequest = (ItemRequest) getNextRequest();
          // Update it
          itemRequest.setId(response.get(0).getId());
      }
  })      // GET /item/{id}   - id is updated in run time by previous request
  .request(new ItemRequest(-1))
  .then(new WoodpeckerResponse<ItemResponse>() {
      @Override
      public void onSuccess(ItemResponse response) {
      }
  })      // POST /review  - JSON encoded post
  .request(new ReviewRequest(1, "Aviran", "This is awesome!"))
  .then(new WoodpeckerResponse<String>() {
      @Override
      public void onSuccess(String response) {
      }
  })      // GET /image.png - request with progress tracking
  .request(new DownloadFileRequest(progressListener))
  .then(new WoodpeckerResponse<InputStream>() {
      @Override
      public void onSuccess(InputStream response) {
      }
  })      // POST multipart data - 2 files uploaded, progress tracking
  .request(createFileUploadRequest())
  .then(new WoodpeckerResponse<UploadResponse>() {
      @Override
      public void onSuccess(UploadResponse response) {
      }
  })     // Error handler for the entire chain
  .error(new WoodpeckerError() {
      @Override
      public void onError(WoodpeckerResponse response) {
      }
  });

Login api call is defined by the following request/response classes

@Post("/login")
public class LoginRequest extends WoodpeckerRequest {
    @Param // @Param used to define 'username' as a request data parameter
    private String username;

    @Param
    private String password;

    public LoginRequest(String username, String password) {
        this.username = username;
        this.password = password;
    }
}

// POJO structure to the response of LoginRequest
public class LoginResponse {
    private String token;

    public String getToken() {
        return token;
    }
}

Item api call - Demonstrating usage of url path variable

@Get("/item/{id}")
public class ItemRequest extends WoodpeckerRequest {
    @Path
    private int id;

    public ItemRequest(int id) {
        this.id = id;
    }

    public void setId(int id) {
        this.id = id;
    }
}

Review api call - Demonstrating posting JSON body

@Post("/review")
public class ReviewRequest extends WoodpeckerRequest {
    // @Param is not used in this class, therefore class structure
    // will be serialized to json, and will be sent as request body.
    private int itemId;
    private String name;
    private String text;

    public ReviewRequest(int itemId, String name, String text) {
        this.itemId = itemId;
        this.name = name;
        this.text = text;
    }
}

GET'ing binary file, with download progress tracking

// Progress listener that will be supplied to the request,
// will be executed on the UI Thread.
progressListener = new WoodpeckerProgressListener() {
    @Override
    public void onProgress(String name, int progress, int totalSize) {
        // log progress / totalSize
    }
}

// By using the @Progress annotation, this request will invoke progress
// notification calls to the supplied listener
@Get("/woodpecker.jpg")
public class DownloadFileRequest extends WoodpeckerRequest {
    @Progress
    WoodpeckerProgressListener progressListener;

    public DownloadFileRequest(WoodpeckerProgressListener progressListener) {
        this.progressListener = progressListener;
    }
}

POST multipart, with upload progress tracking

@Post("/upload")
public class UploadRequest extends WoodpeckerRequest {
    @Param
    private String uploadToken;

    @File
    private WoodpeckerFileStream fileUpload;

    @File
    private WoodpeckerFileStream anotherFileUpload;

    @Progress
    private WoodpeckerProgressListener progressListener;

    public UploadRequest(String uploadToken,
                         WoodpeckerFileStream fileUpload,
                         WoodpeckerFileStream anotherFileUpload,
                         WoodpeckerProgressListener progressListener) {
        this.uploadToken = uploadToken;
        this.fileUpload = fileUpload;
        this.anotherFileUpload = anotherFileUpload;
        this.progressListener = progressListener;
    }
}

License

Copyright 2017 Aviran Abady.

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].