Ratpacked: Include Files In The Ratpack Groovy DSL
When we define our Ratpack application using the Groovy DSL in a file ratpack.groovy, we can split up the definition in multiple files. With the include method inside the ratpack configuration closure...
View ArticleRatpacked: Stub External HTTP Service
Suppose we have a piece of code that uses an external HTTP service. If we write a test for this code we can invoke the real HTTP service each time we execute the tests. But it might be there is …...
View ArticleRatpacked: Use TestHttpClient For External HTTP Services
Ratpack has a very useful class: TestHttpClient. This is a blocking HTTP client that we normally use for testing our Ratpack applications. For example we use MainClassApplicationUnderTest or...
View ArticleRatpacked: Handling Exceptions When Reading Configuration Sources
To define configuration sources for our Ratpack application we have several options. We can set default properties, look at environment variables or Java system properties, load JSON or YAML formatted...
View ArticleRatpacked: Using Groovy Configuration Scripts As Configuration Source
Ratpack has a lot of options to add configuration data to our application. We can use for example YAML and JSON files, properties, environment variables and Java system properties. Groovy has the...
View ArticleRatpacked: Create a Partial Response
Suppose we want to support partial JSON responses in our Ratpack application. The user must send a request parameter with a list of fields that need to be part of the response. In our code we must use...
View ArticleRatpacked: Creating Pairs From Promises
The Pair class in Ratpack is an easy way to create a growing data structure, passed on via Promise methods. A Pair object has a left and right part containing data. These parts can even be other Pair...
View ArticleRatpacked: Easy URI Creation With HttpUrlBUillder
When we need to create a URI object in Ratpack we can use the HttpUrlBuilder class. We use several methods to build up a complete URI object in an easy way. This is very useful when we for example use...
View ArticleRatpacked: Using Spring Cloud Contract To Implement Server
Spring Cloud Contract is a project that allows to write a contract for a service using a Groovy DSL. In the contract we describe the expected requests and responses for the service. From this contract...
View ArticleRatpacked: Using Spring Cloud Contract As Client
In a previous post we learned about Spring Cloud Contract. We saw how we can use contracts to implement the server side of the contract. But Spring Cloud Contract also creates a stub based on the...
View ArticleRatpacked: Implement A Custom Request Parser
Ratpack has parsers to parse a request with a JSON body or a HTML form. We simply use the parse method of Context and Ratpack will check if there is a compliant parser in the registry. If there is a …...
View ArticleRatpacked: Implement Custom Rendering With Renderable Interface
Ratpack uses renderers to render output. We can create our own renderer by implementing the Renderer interface. The renderer class needs to implement a render method that has the object we want to...
View ArticleRatpacked: Type Check And Static Compilation For Groovy DSL
One of the very nice features of Ratpack is the Groovy DSL to define our application. We get a nice DSL to set up the registry, to define handlers and more. Because of clever use of the @DelegateTo...
View ArticleRatpacked: Combine Groovy DSL With RatpackServer Java Configuration
We have several options to define a Ratpack application. We can use a Java syntax to set up the bindings and handlers. Or we can use the very nice Groovy DSL. It turns out we can use both together as …...
View ArticleRatpacked: Override Registry Objects With Mocks In Integration Specifications
Testing a Ratpack application is not difficult. Ratpack has excellent support for writing unit and integration tests. When we create the fixture MainClassApplicationUnderTest we can override the method...
View ArticleRatpacked: Add Ratpack To Spring Boot Application
In a previous post we saw how we can use Spring Boot in a Ratpack application. But the integration can also be the other way around: using Ratpack in a Spring Boot application. This way we can use...
View ArticleRatpacked: Conditionally Map Or Flatmap A Promise
When we want to transform a Promise value we can use the map and flatMap methods. There are also variants to this methods that will only transform a value when a given predicate is true: mapIf and...
View ArticleRatpacked: Assert No Exceptions Are Thrown With RequestFixture
Writing unit tests for our handlers in Ratpack is easy with RequestFixture. We invoke the handle method and use a Handler or Chain we want to test as argument. We can provide extra details on the...
View Article