Giter VIP home page Giter VIP logo

httputil's Introduction

httputil

Easily perform HTTP requests in Java

HttpUtil is a single class containing methods to conveniently perform HTTP requests. HttpUtil only uses regular java io and net functionality and does not depend on external libraries. The class contains methods to perform a get, post, put, and delete request, and supports posting forms. Optionally, one can provide headers.

Usage

Insert the class HttpUtil.java in your project.

Next, the HttpUtil methods can called statically. An GET request looks like:

String res = HttpUtil.get("http://www.google.com");

Examples

// GET
String res = HttpUtil.get("http://www.google.com");

// POST
String res = HttpUtil.post("http://sendmedata.com", "This is the data");

// POST FORM
Map<String, String> params = new HashMap<String, String>();
params.put("firstname", "Joe");
params.put("lastname", "Smith");
params.put("age", "28");
String res = HttpUtil.postForm("http://site.com/newuser", params);

// append query parameters to url
String url = "http://mydatabase.com/users";
Map<String, String> params = new HashMap<String, String>();
params.put("orderby", "name");
params.put("limit", "10");
String fullUrl = HttpUtil.appendQueryParams(url, params);
// fullUrl = "http://mydatabase.com/user?orderby=name&limit=10"

API

HttpUtil contains the following static methods:

String get(String url)
String get(String url, Map<String, String> headers)

String post(String url, String body)
String post(String url, String body, Map<String, String> headers)

String postForm(String url, Map<String, String> params)
String postForm(String url, Map<String, String> params, Map<String, String> headers)

String put(String url, String body)
String put(String url, String body, Map<String, String> headers)

String delete(String url)
String delete(String url, Map<String, String> headers)
    
fetch(String method, String url, String body,	Map<String, String> headers)

String appendQueryParams(String url, Map<String, String> params)
String removeQueryParams(String url)
Map<String, String> getQueryParams(String url)

httputil's People

Contributors

dreamkidd avatar josdejong avatar

Watchers

 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.