HTTP helpers in $util.http
Note
We now primarily support the APPSYNC_JS runtime and its documentation. Please consider using the APPSYNC_JS runtime and its guides here.
The $util.http
utility provides helper methods that you can use to manage
HTTP request parameters and to add response headers.
-
$util.http.copyHeaders(Map) : Map
-
Copies the header from the map without the restricted set of HTTP headers. You can use this to forward request headers to your downstream HTTP endpoint.
{ ... "params": { ... "headers": $util.http.copyHeaders($ctx.request.headers), ... }, ... }
$util.http.addResponseHeader(String, Object)
-
Adds a single custom header with the name (
String
) and value (Object
) of the response. The following limitations apply:-
Header names can't match any of the existing or restricted AWS or AWS AppSync headers.
-
Header names can't start with restricted prefixes, such as
x-amzn-
orx-amz-
. -
The size of custom response headers can't exceed 4 KB. This includes header names and values.
-
You should define each response header once per GraphQL operation. However, if you define a custom header with the same name multiple times, the most recent definition appears in the response. All headers count towards the header size limit regardless of naming.
... $util.http.addResponseHeader("itemsCount", 7) $util.http.addResponseHeader("render", $ctx.args.render) ...
-
$util.http.addResponseHeaders(Map)
-
Adds multiple response headers to the response from the specified map of names (
String
) and values (Object
). The same limitations listed for theaddResponseHeader(String, Object)
method also apply to this method.... #set($headersMap = {}) $util.qr($headersMap.put("headerInt", 12)) $util.qr($headersMap.put("headerString", "stringValue")) $util.qr($headersMap.put("headerObject", {"field1": 7, "field2": "string"})) $util.http.addResponseHeaders($headersMap) ...