Code Monkey home page Code Monkey logo

networkinkt's Introduction

networkinkt Build Status

This is a lightweight HTTP client for Kotlin. It relies on coroutines on both JS & JVM platforms.

Here is a simple GET request:

val text = HTTP.get("http://httpbin.org/status/200").getText() // suspending call

...and a POST request with HTTP headers and body:

val text = HTTP.post("http://httpbin.org/headers",
                     headers = mapOf("MyLibraryHeader" to "networkinkt"),
                     body = "param=value")
               .getText()

See the usage section for more examples.

Getting started

The project uses Gradle to manage dependencies.

Common JVM & JS build.gradle:

allprojects {
    repositories {
        // ...
        maven { url 'https://jitpack.io' }
    }
}

dependencies {
    // ...
    compile "com.egorzh.networkinkt:networkinkt:$networkinkt_version"
}

yourproject-jvm/build.gradle:

dependencies {
    // ...
    compile "com.egorzh.networkinkt:networkinkt-jvm:$networkinkt_version"
}

yourproject-js/build.gradle:

dependencies {
    // ...
    compile "com.egorzh.networkinkt:networkinkt-js:$networkinkt_version"
}

You can always check which version is up-to-date on the releases page

Usage

How to make a request:

  1. Obtain an instance of HTTPRequest from an HTTPClient (the default one is DefaultHTTPClient or simply HTTP)
  2. Send the request and receive an HTTPResponse, which encapsulates the response code and text
  3. Use code and text properties of a response object
import com.egorzh.networkinkt.*

// 1:
val request /* : DefaultHTTPRequest */ = HTTP.get(url = "http://httpbin.org/status/200")

// 2: (from a suspend function or coroutine)
val response /* : DefaultHTTPResponse */ = HTTP.sendRequest(request)

// 3:
val code = response.code
val text = response.text

Customization

You can easily create your own implementations of HTTPClient, for example, to provide caching or error handling functionality.

Apache adapter is an example of using custom HTTPClient.

networkinkt's People

Contributors

egorzhdan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

choey

networkinkt's Issues

Response code?

Hello

How do you get the http status of the response?

New release?

Hello

Could you publish a new release taking in account your latests commits please?

Feature Support for SSLContext

Hi,

Thank you for this awesome http client. I noticed that there is no option to pass an instance of SSLContext within the requests. It would be great to have that option as well for https requests which will enable me and other developers to use a custom list of trusted certificates or even provide a custom client certificate as well for mutual authentication. Would that be possible?

Kinds regards,
Hakan

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.