Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,16 @@ protected CallHttpTaskBuilder() {
public CallHttpTaskBuilder self() {
return this;
}

/**
* Sets the output expression for this task (equivalent to {@code output.as} in YAML).
*
* <p>Uses JSONPath expression syntax (e.g., {@code $.field} to select a field from the result).
*
* @param expr JSONPath expression to extract the desired output value from the task result
* @return this builder for chaining
Comment on lines +38 to +41
*/
public CallHttpTaskBuilder outputAs(String expr) {
return this.output(b -> b.as(expr));
}
Comment thread
matheusandre1 marked this conversation as resolved.
Comment thread
matheusandre1 marked this conversation as resolved.
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,26 @@ public interface BaseCallHttpSpec<SELF extends BaseCallHttpSpec<SELF>> {
*/
List<Consumer<CallHttpTaskFluent<?>>> steps();

default SELF GET() {
default SELF get() {
steps().add(c -> c.method("GET"));
return self();
}

default SELF POST() {
@Deprecated
default SELF GET() {
return get();
}

default SELF post() {
steps().add(c -> c.method("POST"));
return self();
}

@Deprecated
default SELF POST() {
return post();
}

default SELF acceptJSON() {
return header("Accept", "application/json");
}
Expand Down Expand Up @@ -122,6 +132,84 @@ default SELF query(String name, String value) {
return self();
}

default SELF put() {
steps().add(c -> c.method("PUT"));
return self();
}

@Deprecated
default SELF PUT() {
return put();
}

default SELF delete() {
steps().add(c -> c.method("DELETE"));
return self();
}

@Deprecated
default SELF DELETE() {
return delete();
}

default SELF patch() {
steps().add(c -> c.method("PATCH"));
return self();
}

@Deprecated
default SELF PATCH() {
return patch();
}

default SELF head() {
steps().add(c -> c.method("HEAD"));
return self();
}

@Deprecated
default SELF HEAD() {
return head();
}

default SELF options() {
steps().add(c -> c.method("OPTIONS"));
return self();
}

@Deprecated
default SELF OPTIONS() {
return options();
}

default SELF acceptXML() {
return header("Accept", "application/xml");
}

default SELF acceptForm() {
return header("Accept", "application/x-www-form-urlencoded");
}

default SELF acceptText() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you put an acceptJson?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you put an acceptJson?

default SELF acceptJSON() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, really I did not see it.

return header("Accept", "text/plain");
}

default SELF contentTypeJSON() {
return header("Content-Type", "application/json");
}

default SELF contentTypeXML() {
return header("Content-Type", "application/xml");
}

default SELF contentTypeForm() {
return header("Content-Type", "application/x-www-form-urlencoded");
}

default SELF contentTypeText() {
return header("Content-Type", "text/plain");
}

default SELF redirect(boolean redirect) {
steps().add(c -> c.redirect(redirect));
return self();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

public final class CallHttpSpec implements BaseCallHttpSpec<CallHttpSpec>, CallHttpConfigurer {

private final List<Consumer<CallHttpTaskFluent<?>>> steps = new ArrayList<>();
private final List<Consumer<CallHttpTaskBuilder>> steps = new ArrayList<>();
Comment thread
fjtirado marked this conversation as resolved.

public CallHttpSpec() {}

Expand All @@ -34,12 +34,21 @@ public CallHttpSpec self() {
}

@Override
@SuppressWarnings("unchecked")
public List<Consumer<CallHttpTaskFluent<?>>> steps() {
return steps;
// Safe cast because we control that all added consumers accept CallHttpTaskBuilder
return (List) steps;
Comment thread
fjtirado marked this conversation as resolved.
}

@Override
public void accept(CallHttpTaskBuilder builder) {
BaseCallHttpSpec.super.accept(builder);
}
Comment on lines 43 to 46

@Override
public CallHttpSpec andThen(Consumer<? super CallHttpTaskBuilder> after) {
// Convert Consumer<? super CallHttpTaskBuilder> to Consumer<CallHttpTaskBuilder> for storage
steps.add(builder -> after.accept(builder));
return this;
Comment on lines +49 to +52
}
Comment thread
matheusandre1 marked this conversation as resolved.
Comment thread
fjtirado marked this conversation as resolved.
}
Loading
Loading