rest-contract

An API for describing a REST contract via examples. This provides a client and a server that will run according to the rules in this contract. This was designed with testing RESTful clients and RESTful services independently.

License

License

GroupId

GroupId

org.christor
ArtifactId

ArtifactId

rest-contract
Last Version

Last Version

0.6
Release Date

Release Date

Type

Type

jar
Description

Description

rest-contract
An API for describing a REST contract via examples. This provides a client and a server that will run according to the rules in this contract. This was designed with testing RESTful clients and RESTful services independently.
Source Code Management

Source Code Management

https://github.com/christor/rest-contract

Download rest-contract

How to add to project

<!-- https://jarcasting.com/artifacts/org.christor/rest-contract/ -->
<dependency>
    <groupId>org.christor</groupId>
    <artifactId>rest-contract</artifactId>
    <version>0.6</version>
</dependency>
// https://jarcasting.com/artifacts/org.christor/rest-contract/
implementation 'org.christor:rest-contract:0.6'
// https://jarcasting.com/artifacts/org.christor/rest-contract/
implementation ("org.christor:rest-contract:0.6")
'org.christor:rest-contract:jar:0.6'
<dependency org="org.christor" name="rest-contract" rev="0.6">
  <artifact name="rest-contract" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.christor', module='rest-contract', version='0.6')
)
libraryDependencies += "org.christor" % "rest-contract" % "0.6"
[org.christor/rest-contract "0.6"]

Dependencies

compile (3)

Group / Artifact Type Version
org.projectlombok : lombok jar 0.11.8
com.sun.jersey : jersey-client jar 1.17.1
com.sun.jersey : jersey-grizzly2 jar 1.17.1

test (1)

Group / Artifact Type Version
junit : junit jar 4.11

Project Modules

There are no modules declared in this project.

rest-contract

An API for describing a REST contract via examples. This provides a client and a server that will run according to the rules in this contract. This was designed with testing RESTful clients and RESTful services independently.

Create a Contract

    Contract contract = new Contract();
    contract.rule(Request.get("api/v1/"), 
                  Response.code(200).body("ThoughtStreams API")
                          .header("Content-Type", "text/plain"));
    contract.rule(Request.get("foo"), 
                  Response.code(200)
                          .body("bar")
                          .header("Content-Type", "text/plain"));
    contract.rule(Request.get("fooh"), 
                  Response.code(200)
                          .body("bar")
                          .header("Content-Type", "text/html"));
    contract.rule(Request.get("asdfasdfa"), 
                  Response.code(404).body("Go away")
                          .header("Content-Type", "text/html"))
            .then(Request.get("asdfasdfa"), 
                  Response.code(404)
                          .body("Go away or I will taunt you a second time")
                          .header("Content-Type", "text/html"));

Create a Server that will follow the rules

    new ContractServer().start("http://localhost:5555/", contract);

you can now test your RESTful client against this

Create a Client and run the rules

    ContractClient client = new ContractClient(contract);
    client.run("http://localhost:5555/");

you can now test your RESTful service using this

Versions

Version
0.6