OpenFeign/feign · error · IllegalArgumentException
Invalid HTTP Method
Error message
Invalid HTTP Method: ${method} What it means
RequestTemplate.method(String) parses the given string into an HttpMethod enum via HttpMethod.valueOf. If the string is not a valid HTTP method name, the resulting IllegalArgumentException is rethrown with 'Invalid HTTP Method: <method>'.
Solutions
- Pass a standard uppercase HTTP method name, e.g. method("GET")
- Trim and normalize case: HttpMethod.valueOf(method.trim().toUpperCase()) before calling
- Fix the annotation or config value supplying the method string
- Prefer the typed method(HttpMethod) overload to get compile-time safety
Example fix
// before
template.method("Get");
// after
template.method("GET"); // or template.method(HttpMethod.GET) Defensive patterns
Strategy: validation
Validate before calling
if (java.net.http.HttpMethod.includes == null) { /* Java 8-safe check */ }
java.util.Set<String> VALID = java.util.Set.of("GET","POST","PUT","DELETE","PATCH","HEAD","OPTIONS","TRACE");
if (!VALID.contains(method.trim().toUpperCase())) {
throw new IllegalArgumentException("Unsupported method: " + method);
} Try / catch
try {
template.method(name);
} catch (IllegalArgumentException e) {
if (e.getMessage() != null && e.getMessage().startsWith("Invalid HTTP Method")) {
LOGGER.warn("Falling back to GET; invalid method {}", name);
template.method("GET");
} else { throw e; }
} Prevention
- Use the typed method(HttpMethod) overload instead of strings
- Normalize case and trim strings from config/annotations before use
- Validate HTTP verbs from external config at load time
When it happens
Trigger: Calling RequestTemplate.method("GETS") or any string that is not a standard HTTP method token (GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS, TRACE) when building a template programmatically or via a misconfigured contract.
Common situations: Typo in a custom Contract/annotation parser, reading the HTTP verb from configuration or an annotation value with a typo, lowercasing methods before passing them in.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- url values must be not be absolute.
- name is required.
- Method return type is not parameterized
- Wildcards are not supported for return-type parameters
- template has not been resolved.
AI-assisted analysis of OpenFeign/feign@e2a1e27560 (2026-09-10).
Data as JSON: /api/errors/a51b0e720bf542e1.
Report an issue: GitHub.
Appendix: source
Thrown at core/src/main/java/feign/RequestTemplate.java:307
throw new IllegalStateException("template has not been resolved.");
}
return Request.create(this.method, this.url(), this.headers(), this.body, this);
}
/**
* Set the Http Method.
*
* @param method to use.
* @return a RequestTemplate for chaining.
* @deprecated see {@link RequestTemplate#method(HttpMethod)}
*/
@Deprecated
public RequestTemplate method(String method) {
checkNotNull(method, "method");
try {
this.method = HttpMethod.valueOf(method);
} catch (IllegalArgumentException iae) {
throw new IllegalArgumentException("Invalid HTTP Method: " + method);
}
return this;
}
/**
* Set the Http Method.
*
* @param method to use.
* @return a RequestTemplate for chaining.
*/
public RequestTemplate method(HttpMethod method) {
checkNotNull(method, "method");
this.method = method;
return this;
}
/**
* The Request Http Method.View on GitHub (pinned to e2a1e27560)