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

uriahcarpenter avatar sagebind avatar aswenson avatar bwoestman avatar cschroeder avatar

Stargazers

Jiri Jagos avatar  avatar Mark Feltner avatar  avatar

Watchers

Ben Dotte avatar  avatar  avatar  avatar  avatar James Cloos avatar Nathan Mall avatar Widen Developers avatar  avatar  avatar Griff Lochner avatar Joshua Ard avatar  avatar Rich Vertz avatar Adam Pergande avatar  avatar Matt Frank avatar  avatar  avatar Kevin Brinnehl avatar Adam Knutson avatar  avatar  avatar Jose Avalos avatar Cristian Castillo avatar  avatar

urlbuilder's Issues

BuiltinEncoder does not handle '+' correctly

Hey. If, for any reason, parts of my URL originally contain the '+' character, it is later replaced by '%20', the equivalent to space. This is ok for most cases, but not completely correct.

Fix URL encoding of path segments

Path segments are currently not encoded correctly and do not follow the URL spec. Path and query should be encoded differently, but UrlBuilder uses one implementation for everything.

Migrate package name

Currently all the classes in this package are in the general com.widen.util namespace. They should be moved to the more specific com.widen.urlbuilder package. This is a breaking change, so do this as part of the 2.0 release.

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.