aah Request and Response

This document provides an insights into aah Request and Response capabilities. So that it could be utilized effectively.

Table of Contents

Request

aah Request extends form of standard request struct. It provides necessary values (derived and processed per RFCs).

Fields

Field NameDescription
SchemeRequest protocol value https or http, it’s a inferred value. Know more
HostValue of correct Host source from HTTP request
MethodValue of HTTP verb name, such as GET, POST, etc
PathRequest URL Path e.g. /app/login.html
HeaderHTTP request headers
PathParamsURL path parameters values that was defined routes.conf
RefererValue of HTTP header Referer or Referrer
UserAgentValue of HTTP header User-Agent
IsGzipAcceptedInferred value as bool, whether HTTP client supports Gzip compression or not.

Methods

Method NameDescription
AcceptContentTypeNegotiated value of HTTP Header Accept. The resolve order is URL extension, Accept header per RFC7231 and Vendor Types per RFC4288
AcceptEncodingNegotiated value of HTTP Header the Accept-Encoding per RFC7231
ContentTypeParsed value of HTTP header Content-Type per RFC1521
BodyReturns the HTTP request body io.ReadCloser
SaveFileSaves an uploaded request multipart file for the given key into given destination file
LocaleNegotiated value of HTTP Header Accept-Language per RFC7231
ClientIPReturns remote Client IP address aka Remote IP. It parses in the order of given set of headers otherwise it uses default header set X-Forwarded-For, X-Real-IP, X-Appengine-Remote-Addr and finally http.Request.RemoteAddr
CookieReturns a named cookie from HTTP request otherwise error
CookiesReturns all the cookies from HTTP request
IsJSONPReturns true if request URL query string has callback=<function_name>
IsAJAXReturns true if request header X-Requested-With is XMLHttpRequest otherwise false
URLReturns request URL instance
UnwrapReturns the underlying *http.Request instance of Go HTTP server, direct interaction with raw object is not encouraged.

It is highly recommended to use Auto Parse and Bind feature on controller action arguments. Non-controller (like middleware, etc.) location use following method appropriately.


Method NameDescription
PathValueReturns value for given Path param key otherwise empty string. For eg.: /users/:userId => PathValue("userId")
QueryValueReturns value for given URL query param key otherwise empty string
QueryArrayValueReturns array value for given URL query param key otherwise empty string slice
FormValueReturns value for given form key otherwise empty string
FormArrayValueReturns array value for given form key otherwise empty string slice
FormFileReturns the first file for the provided form key otherwise returns error. It is caller responsibility to close the file

Response

aah resposne writer implements interfaces http.ResponseWriter, http.CloseNotifier, http.Flusher, http.Hijacker, http.Pusher and io.Closer.

And captuers following details -

  • Status() - returns response status code
  • BytesWritten() - returns the total number of bytes written into response
  • Unwrap() - returns the underlying ResponseWriter

It is highly recommended to use Reply Builder to compose response.