hmrc / url-builder

Micro-library for building URLs from templates and tags

GitHub

URL Builder

Build Status Download

Micro-library for building URLs from templates and tags.

  • Creates links with settings that are appropriate to the target. See Link's companion object:
Links.toInternalPage            // No SSO, Same Window
Links.toExternalPage            // No SSO, New Window
Links.toPortalPage              // Client-based SSO, Same Window
Links.toInternalPageWithSso     // Server-based SSO, Same Window
  • Constructs parametrized urls based on the tags and corresponding values provided.

Usage

  • Link can be used in scala html templates to generate consistent links across a page:
@import uk.gov.hmrc.urls.Link
<li>
  @{Link.toPortalPage(id = Some("link-id"), 
                      url = "http://someserver:8080/something", 
                      value = Some("Placeholder text displayed for the link")).toHtml}
</li>
  • UrlBuilder can be used to build a URL based on parameters from a (tag, value) map:
UrlBuilder.buildUrl("http://server:8080/something/<tag1>/<tag2>",
                     Seq("<tag1>"->Some("value1"), "<tag2>"->Some("value2"))
                    )

would produce the url: http://someserver:8080/something/value1/value2

Adding to your service

Include the following dependency in your SBT build

resolvers += Resolver.bintrayRepo("hmrc", "releases")

libraryDependencies += "uk.gov.hmrc" %% "url-builder" % "x.x.x"

License

This code is open source software licensed under the Apache 2.0 License.