GithubHelp home page GithubHelp logo

jcurl's Introduction

Welcome to Viaplay jCurl project

JCurl is a simple yet powerful resource getter that works very much like the curl command line tool we all have used and learned to love. In its simplest form it fetches data from an entered url and return that data in a form of a String for further processing or direct use.

Why static methods?

All parameters that conducts the behavior of jCurl fits in the JCurlRequest object that is passed into the jCurl request functions. Therefore this approach prevents creating an unnecessary object.

How to use it?

As always the best way to learn is to read and use the JUnit test classes, in this case the JCurlTest.java.

A get request in its simplest form

To get a HTML resource from the Internet is a very easy task:

String htmlCode = JCurl.get("http://localhost:1962/").toString;

When communicating with a REST web service

Here is a sample of how you can use JCurl to create a CouchDB database and fill it with data. To be reusable it also checks if the database exists in the beginning and deletes it if it does.

	SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss-SSS");
	String databaseUrl = "http://username:password@couchdb:5984/jcurltestdb";

	/* Check if the database exists and delete if so */
	JCurlResponse response = JCurl.head(databaseUrl);
	if (response.getResponseCode() == 200) {
		JCurl.delete(databaseUrl);
	}
	/* Create the database */
	response = JCurl.put(databaseUrl, null);

	/* Fill the database */
	for (int i = 0; i < 100; i++) {
		Date now = new Date();
		String dateString = dateFormat.format(now);
		response = JCurl.put(String.format("%s/%s", databaseUrl, dateString),
				String.format("{\"time\":\"%s\", \"no\":%s}", dateString, i));
	}

Take advantage of server cookies in subsequent requests

The latest addition to the JCurl project is the JCurlCookieManager which retrieves all cookies from the responses and adds the valid ones to the request.

JCurl.get("some.url", JCurlCookieManager.getInstance());
JCurl.get("some.url/here?we=need&cookies", JCurlCookieManager.getInstance());

jcurl's People

Contributors

fredr avatar lpmi-13 avatar mlromramse avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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