Giter Club home page Giter Club logo

asynchttpclient's Introduction

#AsyncHttpClient by Callum Taylor

Build Status

Follow me on Twitter | App.net | Website | Blog

This is the new and improved version of AsyncHttpClient taken from X-Library. It was long due a re-write.

In this version it allows a more flexible usage of posting files, http entities and GZIP handling.

The library uses Square's OKHTTP library.

It consists of 2 different classes, AsyncHttpClient and SyncHttpClient. Obviously by the name, AsyncHttpClient is for asynchronous requests which uses the AsyncTask paradigm, and SyncHttpClient is for synchronous requests which should be handled by yourself in a thread outside of the UI thread.

#Usage

Simply import the gradle file into Android Studio and reference the dependancy in your settings.gradle and project's build.gradle

Alternatively you can add the maven dependancy net.callumtaylor:asynchttpclient:2.0 N.B. Do NOT use net.callumtaylor.asynchttp for the group ID. This is an old ID and will NOT be updated

#Table of contents

#Other notes ###Downloading large files

In order to download large files, you will need to subclass AsyncHttpResponseHandler and override the onByteChunkReceived() method to write directly to cache instead of appending to a ByteArrayOutputStream which is what the standard BinaryResponseHandler does. This is to stop OOM due to a over-sized output stream.

###AsyncHttpClient

Note: Because AsyncHttpClient uses AsyncTask, only one instance can be created at a time. If one client makes 2 requests, the first request is canceled for the new request. You can either wait for the first to finish before making the second, or you can create two seperate instances. See: Example custom handler for more.

###SyncHttpClient

SyncHttpClient is a paramitized class which means the type you infer to it, is the type that gets returned when calling the method. When supplying a ResponseHandler, that ResponseHandler must also paramitized with the same type as the SyncHttpClient instance.

You can also get the info of the request by calling your SyncHttpClient instance and getConnectionInfo(). This can only be called after the response has been completed.

Note: Because Android requires all network requests to be performed outside the UI thread, you must use SyncHttpClient sparingly and make sure you handle the operaion OFF the UI thread.

Because of the nature of REST, GET and DELETE requests behave in the same way, POST and PUT requests also behave in the same way.

#License

See library/LICENSE

asynchttpclient's People

Contributors

scruffyfox avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.