true is the resource exists in the classpath.
Returns the result of applying f to this resource if it exists.
Returns the result of applying f to this resource if it exists. Otherwise evaluates the
ifMissing
expression.
the value to be return if the resource is missing.
the function to apply to the resource if it exists.
a value of type A
.
maybe the java.io.InputStream
for the resource if it exists in the classpath.
A resource than can be read from the classpath.
Ok(ClasspathResource("/public/index.html"))
A common use case is to serve static resources (html, js, images files) from the classpath. ClasspathResource values can be directly encoded as Content and used to feed an HTTP response.
Trying to write a missing resource on an HTTP response will close the connection.
Also, this provide a basic security by requiring the path to be asbolutely defined. No directory navigation is allowed. For example
ClasspathResource("/public/../public/index.html")
will resolve to a missing resource.