Giter Club home page Giter Club logo

resting's Introduction

resting Build Status

Easy REST API testing library

What is Resting??

REST + TESTING = RESTING

Resting is a simple and light weight library for accessing REST API with little fuss. You can use Resting as a REST client for consuming REST services in your application or You can use it for end-to-end testing of your REST services. The main features are:

  • Simple and Easy to use
  • Fluent API
  • Convention over Configuration
  • Secured API call support(Basic Auth + Token)
  • Request builder and JSON File payload support
  • State-less and State-full(Cookie) Service invocation
  • REST JSON and XML Service support
  • BDD Style Fluent API
  • Less code, Less Bug

Installation

Resting is a java library, So you can download the resting-x.x.x.jar and directly consume in your application however we are recommending to use a build system like Maven or Gradle. Please refer to below sections based on your build system:

  • Maven

    You can add below dependency to your pom.xml:

     <dependency>
         <groupId>com.anitechcs</groupId>
         <artifactId>resting</artifactId>
         <version>0.0.1</version>
     </dependency>
    
  • Gradle

    You can add below dependency to your build.gradle file:

     dependencies {
         compile group: 'com.anitechcs', name: 'resting', version: '0.0.1'
     }
     
     Or in Short
     
     dependencies {
     	compile 'com.anitechcs:resting:0.0.1'
     }
    
  • Custom (Not recommended)

    Download resting-0.0.1-SNAPSHOT.jar and add to your classpath along with following dependent library jars:

    • JUnit
    • Log4J2
    • Apache HTTP Client
    • Json-Simple

Getting Started

Once you have resting in your classpath (Refer #Installation section), you are ready to take it for a spin. You need to get a handle to Resting instance first:

Resting resting = Resting.getInstance();

Also you can configure few things globally with provided fluent API like below:

Resting	resting = Resting
				.getInstance()
				.enableMetrics()  //enable metrics
				.enableProcessingHooks()  //enables pre and post processing hooks
				.globalRequestConfig(globalConfig)  //global request configuration
				.baseURI("https://jsonplaceholder.typicode.com");  //set base URL

Enjoy calling your REST services through Resting with less code and easier API:

Header

// Header array
Header[] headers = {
    new Header("Content-Type", "application/json"),
    new Header("Accept", "application/xml,text/plain,application/json"),
    new Header("Connection", "keep-alive")
};

// Single Header
Header header = new Header("Content-Type", "application/json");

RequestConfig (Optional)

RequestConfig config = new RequestConfig();
config.setConnectTimeout(5000);
config.setSocketTimeout(5000);

config.setHeaders(headers);
config.addHeader(header);
config.addHeader(new Header("Content-Type", "application/json"));
config.addHeader("Content-Type", "application/json");

GET

// GET Without Extra Config
RestingResponse res = resting.GET("/posts/1");
JSONObject json = (JSONObject) res.getBody();

// GET Without Extra Config - Multiple records
RestingResponse res = resting.GET("/posts");
JSONArray jsonArr = (JSONArray) res.getBody();
	
// GET With Extra Config
RestingResponse res = resting.GET("/posts/1", config);
JSONObject json = (JSONObject) res.getBody();

POST

// POST Without Extra Config
RestingResponse res = resting.POST("/posts", inputs);
JSONObject json = (JSONObject) res.getBody();
	
// POST With Extra Config	
RestingResponse res = resting.POST("/posts", inputs, config);
JSONObject json = (JSONObject) res.getBody();

PUT

// PUT Without Extra Config
RestingResponse res = resting.PUT("/posts/1", inputs);
JSONObject json = (JSONObject) res.getBody();
	
// PUT With Extra Config	
RestingResponse res = resting.PUT("/posts/1", inputs, config);
JSONObject json = (JSONObject) res.getBody();

DELETE

// DELETE Without Extra Config
RestingResponse res = resting.DELETE("/posts/1");
JSONObject json = (JSONObject) res.getBody();
	
// DELETE With Extra Config
RestingResponse res = resting.DELETE("/posts/1", config);
JSONObject json = (JSONObject) res.getBody();

Supported Payload (Input Data) Formats

For POST and PUT services you need to pass payload to the service. You can see syntax wise we are accepting Object type which means you can pass your data in any supported format below and Resting will take care of the rest.

  • Map
  • JSON String (e.g. {"name": "Tapas", "country": "India"})
  • JSONObject
  • StringBuffer
  • StringBuilder
  • File (e.g. new File("/data/input.json"))
  • InputStream
  • FileInputStream

If you still need more input format support, Please let us know!

Note

Make sure you are importing RequestConfig and Header from Resting library instead of Apache HTTP library

Got a feedback?

We really appriciate your feedback and looking forward to make Resting better and better. Please raise a defect or pull request if you want to discuss anything with us regarding Resting

resting's People

Contributors

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