Skip to content

Martini URL Functions

Overview

The Url class in Martini provides a suite of utility functions designed for URL manipulation. These functions are essential for handling various aspects of URLs, including extraction of specific parts and constructing URLs from HttpServletRequest objects. This documentation focuses on demonstrating the use of UrlFunctions in a Groovy context.

Using UrlFunctions

Groovy offers a straightforward approach to utilize UrlFunctions. The following examples illustrate some common use cases:

Example 1: Retrieving Base URL from a HttpServletRequest

This example demonstrates how to obtain the base URL from a HttpServletRequest object.

1
2
3
4
5
// Assume 'request' is an existing HttpServletRequest object
def request = ...

// Extracting the base URL from the request
def baseUrl = request.getBaseUrl()

Example 2: Extracting File Name from URL

In this example, we extract the file name from a URL using the filenameFromUrl method.

1
2
// Assuming 'baseUrl' contains the full URL
def fileName = baseUrl.filenameFromUrl()