Giter Club home page Giter Club logo

urlbuilder's Introduction

UrlBuilder

Build Status Maven Central

Utility class for constructing syntactically correct HTTP URLs using a fluent method-chaining API. It strives simply to be more robust than manually constructing URLs by string concatenation.

Made with ❤️ by Widen.

Features

  • Automatic slash management in paths. Slashes will be de-duped or added as necessary when using addPathSegment
  • Automatic URL encoding for both path segments (preserving slashes) and query parameters
    • Encoder is user replaceable; two implementations are provided:
      • Default BuiltinEncoder uses java.net.UrlEncoder
      • NoEncodingEncoder uses text as-is
      • Use usingEncoder(Encoder encoder) to set default; addParameter(String key, Object value, Encoder encoder) can be used to override Encoder for a single parameter
  • Options for generation of fully-qualified, hostname relative, or protocol relative URLs
  • Fluent method-chaining API
  • More examples in UrlBuilderTest

Installation

With Gradle:

compile 'com.widen:urlbuilder:{version}'

Other dependency managers should be similar.

Usage

new UrlBuilder("my.host.com", "foo").addPathSegment("bar").addParameter("a", "b").toString()

produces http://my.host.com/foo/bar?a=b

new UrlBuilder("my.host.com", "foo & bar").addParameter("1&2", "3&4").addParameter("a", "b&c").toString()

produces http://my.host.com/foo%20%26%20bar?1%262=3%264&a=b%26c

S3 Flavored UrlBuilder

  • S3UrlBuilder provides specialized functionality building for S3 URLs
  • expireIn and expireAt for time-bombing S3 links
  • All bucket reference methods supported:
    • virtual bucket (http://bucket.example.com/key.txt)
    • bucket in path (https://s3.amazonaws.com/bucket.example.com/key.txt)
    • hostname (http://bucket.example.com.s3.amazonaws.com/key.txt)
  • withAttachmentFilename(String filename) generates required Content-Disposition header for browser file download prompt

Cloudfront Flavored UrlBuilder

  • CloudfrontUrlBuilder provides specialized functionality for building CloudFront URLs
  • expireIn and expireAt for time-bombing CloudFront links
  • withAttachmentFilename(String filename) generates required Content-Disposition header for browser file download prompt

License

Licensed under the Apache Version 2.0 license. See the license file for details.

urlbuilder's People

Contributors

aswenson avatar bwoestman avatar cschroeder avatar sagebind avatar uriahcarpenter 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.