All Downloads are FREE. Search and download functionalities are using the official Maven repository.

templates.post.Java.handlebars Maven / Gradle / Ivy

{{type}} {{name}} = new {{type}}();
// TODO populate {{name}} object

HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
        .uri(URI.create(baseUrl{{#each chunks}} + {{#unless this.param}}"{{/unless}}{{this.path}}{{#unless this.param}}"{{/unless}}{{/each}}))
        .setHeader("Content-Type", "application/json")
        .setHeader("Authorization", "Bearer " + authToken)
        .POST(HttpRequest.BodyPublishers.ofString(new Gson().toJson({{name}})))
        .build();

HttpResponse response = client.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() == HttpURLConnection.HTTP_CREATED) {
    String location = response.headers().firstValue("Location").get();
    System.out.println("Created {{name}} at: " + baseUrl + location);
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy