R/html-api-gateway-events.R

Defines functions handle_event_error.html_api_gateway_event serialise_result.html_api_gateway_event parse_event_content.html_api_gateway_event is_from_html_api_gateway

Documented in is_from_html_api_gateway

#' Determine if a Lambda event is coming via an API Gateway
#'
#' @inheritSection is_from_rest_api_gateway Invocations via an API Gateway
#'
#' @inheritParams classify_event
#'
#' @return logical
#' @keywords internal
is_from_html_api_gateway <- function(event_content) {
  grepl("routeKey", event_content)
}

#' @export
parse_event_content.html_api_gateway_event <- function(event, config, ...) {
  parsed_json <- parse_json_or_empty(event$event_content)

  query_string_parameters <- parsed_json[["queryStringParameters"]]
  query_parameters <- if (is.null(query_string_parameters)) {
    list()
  } else {
    # convert "value1,value2" to c("value1", "value2")
    Map(
      function(x) strsplit(x, ",")[[1]],
      query_string_parameters
    )
  }

  # Parse the JSON within the JSON
  body <- parsed_json[["body"]]
  base64_encoded <- parsed_json[["isBase64Encoded"]]
  body_parameters <- decode_html_body(body, config, base64_encoded)

  # query parameters always named, should go last
  c(body_parameters, query_parameters)
}

#' @export
serialise_result.html_api_gateway_event <- function(event, ...) {
  serialise_result.rest_api_gateway_event(event, ...)
}

#' @export
handle_event_error.html_api_gateway_event <- function(event, ...) {
  handle_event_error.rest_api_gateway_event(event, ...)
}

Try the lambdr package in your browser

Any scripts or data that you put into this service are public.

lambdr documentation built on Nov. 25, 2023, 5:08 p.m.