Giter Site home page Giter Site logo

poojagidaveer / java-httpbin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gaul/java-httpbin

0.0 0.0 0.0 161 KB

A Java-based HTTP server that lets you locally test your HTTP client, retry logic, streaming behavior, timeouts, etc. with the endpoints of httpbin.org

License: Apache License 2.0

Java 91.90% HTML 8.10%

java-httpbin's Introduction

Java httpbin

Build Status Maven Central

A Java-based HTTP server that lets you locally test your HTTP client, retry logic, streaming behavior, timeouts, etc. with the endpoints of httpbin.org.

This way, you can write tests without relying on an external dependency like httpbin.org.

Endpoints

Java httpbin supports a subset of httpbin endpoints:

  • /ip Returns Origin IP.
  • /user-agent Returns user-agent.
  • /headers Returns headers.
  • /delete Returns DELETE data.
  • /get Returns GET data.
  • /patch Returns PATCH data.
  • /post Returns POST data.
  • /put Returns PUT data.
  • /anything Returns anything passed in request data.
  • /status/:code Returns given HTTP Status code.
  • /redirect/:n 302 Redirects n times.
  • /relative-redirect/:n 302 Redirects n times.
  • /absolute-redirect/:n 302 Absolute redirects n times.
  • /redirect-to?url=foo 302 Redirects to the foo URL.
  • /stream/:n Streams n lines of JSON objects.
  • /stream-bytes/:n?chunkSize=c&seed=s Streams n bytes.
  • /delay/:n Delays responding for min(n, 10) seconds.
  • /bytes/:n Generates n random bytes of binary data, accepts optional seed integer parameter.
  • /base64/:s Returns a base64 decoded :s input
  • /range/:s Return a subset of data based on Content-range header.
  • /cookies Returns the cookies.
  • /cookies/set?name=value Sets one or more simple cookies.
  • /cookies/delete?name Deletes one or more simple cookies.
  • /drip?numbytes=n&duration=s&delay=s&code=code Drips data over a duration after an optional initial delay, then optionally returns with the given status code.
  • /cache Returns 200 unless an If-Modified-Since or If-None-Match header is provided, when it returns a 304.
  • /cache/:n Sets a Cache-Control header for n seconds.
  • /etag Return 200 when If-Match or If-None-Match succeed.
  • /gzip Returns gzip-encoded data.
  • /deflate Returns deflate-encoded data.
  • /robots.txt Returns some robots.txt rules.
  • /deny Denied by robots.txt file.
  • /basic-auth/:user/:passwd Challenges HTTP Basic Auth.
  • /hidden-basic-auth/:user/:passwd Challenges HTTP Basic Auth and returns 404 on failure.
  • /html Returns some HTML.
  • /xml Returns some XML.
  • /image/png Returns page containing a PNG image.
  • /image/jpeg Returns page containing a JPEG image.

Usage

First add dependency to pom.xml:

<dependency>
  <groupId>org.gaul</groupId>
  <artifactId>httpbin</artifactId>
  <version>1.3.0</version>
</dependency>

Then add to your test code:

private URI httpBinEndpoint = URI.create("http://127.0.0.1:0");
private final HttpBin httpBin = new HttpBin(httpBinEndpoint);

@Before
public void setUp() throws Exception {
    httpBin.start();

    // reset endpoint to handle zero port
    httpBinEndpoint = new URI(httpBinEndpoint.getScheme(),
            httpBinEndpoint.getUserInfo(), httpBinEndpoint.getHost(),
            httpBin.getPort(), httpBinEndpoint.getPath(),
            httpBinEndpoint.getQuery(), httpBinEndpoint.getFragment());
}

@After
public void tearDown() throws Exception {
    httpBin.stop();
}

@Test
public void test() throws Exception {
    URI uri = URI.create(httpBinEndpoint + "/status/200");
    HttpURLConnection conn = (HttpURLConnection) uri.toURL().openConnection();
    assert conn.getResponseCode() == 200;
}

References

License

Copyright (C) 2018-2019 Andrew Gaul
Copyright (C) 2015-2016 Bounce Storage

Licensed under the Apache License, Version 2.0

java-httpbin's People

Contributors

gaul avatar dependabot[bot] avatar sullis avatar farnulfo avatar snorp avatar mgrand 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.