dev.mccue/urlparametersdev.mccue.urlparametersbowbahdoe/urlparametersurlparameters provides the logic needed to read and write "URL parameters."
This covers both query parameters, often seen at the end of a URL (google.com?q=apples&track_id=123), and the bodies of html form submissions (name=bob&age=98).
It uses com.uwyn.urlencoder to properly encode parameters for both situations.
Most websites eventually encode some information as query parameters inside a URL. urlparameters lets you extract that information as well as produce such URLs.
It is also common for websites to accept information from a user via a form submission - more so if you server-side render HTML. Processing those form submissions means parsing those request bodies.
import java.net.URI;
import dev.mccue.urlparameters.UrlParameters;
void main() {
var url = URI.create("https://google.com?q=pear");
var params = UrlParameters.parse(url);
System.out.println(params.firstValue("q").orElseThrow());
}import dev.mccue.urlparameters.UrlParameters;
void main() {
var body = "name=jack&title=squire";
var params = UrlParameters.parse(body);
// squire
System.out.println(params.firstValue("title").orElseThrow());
}import java.util.List;
import java.net.URI;
import dev.mccue.urlparameters.UrlParameters;
import dev.mccue.urlparameters.UrlParameter;
void main() {
var params = new UrlParameters(List.of(
new UrlParameter("pokemon", "stantler"),
new UrlParameter("caught_in", "Pokemon Colosseum")
));
var url = URI.create("https://example.com?" + params);
// https://example.com?pokemon=stantler&caught_in=Pokemon%20Colosseum
System.out.println(url);
}