static/jsvm/interfaces/router.Event.html
Event specifies based Route handler event that is usually intended to be embedded as part of a custom event struct.
NB! It is expected that the Response and Request fields are always set.
badRequestErrorbindBodybloberrorfileFSfindUploadedFilesflushforbiddenErrorgetgetAllhtmlinternalServerErrorisTLSjsonnextnoContentnotFoundErrorredirectremoteIPsetsetAllsetCookiestatusstreamstringtooManyRequestsErrorunauthorizedErrorwrittenxml
BindBody unmarshal the request body into the provided dst.
dst must be either a struct pointer or map[string]any.
The rules how the body will be scanned depends on the request Content-Type.
Currently the following Content-Types are supported:
- application/json - text/xml, application/xml - multipart/form-data, application/x-www-form-urlencodedCopy
Respectively the following struct tags are supported (again, which one will be used depends on the Content-Type):
- "json" (json body)- uses the builtin Go json package for unmarshaling. - "xml" (xml body) - uses the builtin Go xml package for unmarshaling. - "form" (form data) - utilizes the custom [router.UnmarshalRequestData] method.Copy
NB! When dst is a struct make sure that it doesn't have public fields that shouldn't be bindable and it is advisible such fields to be unexported or have a separate struct just for the binding. For example:
data := struct{ somethingPrivate string Title string `json:"title" form:"title"` Total int `json:"total" form:"total"` } err := e.BindBody(&data)Copy
Blob writes a blob (bytes slice) response.
FileFS serves the specified filename from fsys.
It is similar to [echo.FileFS] for consistency with earlier versions.
FindUploadedFiles extracts all form files of "key" from a http request and returns a slice with filesystem.File instances (if any).
Flush flushes buffered data to the current response.
Returns [http.ErrNotSupported] if e.Response doesn't implement the [http.Flusher] interface (all router package handlers receives a ResponseWritter that implements it unless explicitly replaced with a custom one).
Get retrieves single value from the current event data store.
GetAll returns a copy of the current event data store.
HTML writes an HTML response.
IsTLS reports whether the connection on which the request was received is TLS.
JSON writes a JSON response.
It also provides a generic response data fields picker if the "fields" query parameter is set. For example, if you are requesting ?fields=a,b for e.JSON(200, map[string]int{ "a":1, "b":2, "c":3 }), it should result in a JSON response like: {"a":1, "b": 2}.
Next calls the next hook handler.
NoContent writes a response with no body (ex. 204).
Redirect writes a redirect response to the specified url. The status code must be in between 300 – 399 range.
RemoteIP returns the IP address of the client that sent the request.
IPv6 addresses are returned expanded. For example, "2001:db8::1" becomes "2001:0db8:0000:0000:0000:0000:0000:0001".
Note that if you are behind reverse proxy(ies), this method returns the IP of the last connecting proxy.
Set saves single value into the current event data store.
SetAll saves all items from m into the current event data store.
SetCookie is an alias for [http.SetCookie].
SetCookie adds a Set-Cookie header to the current response's headers. The provided cookie must have a valid Name. Invalid cookies may be silently dropped.
Status reports the status code of the current response.
This method always returns 0 if e.Response doesn't implement the StatusTracker interface (all router package handlers receives a ResponseWritter that implements it unless explicitly replaced with a custom one).
Stream streams the specified reader into the response.
String writes a plain string response.
Written reports whether the current response has already been written.
This method always returns false if e.ResponseWritter doesn't implement the WriteTracker interface (all router package handlers receives a ResponseWritter that implements it unless explicitly replaced with a custom one).
XML writes an XML response. It automatically prepends the generic [xml.Header] string to the response.
Optional requestrequest?: Request
response: ResponseWriter
OSLightDark
Generated using TypeDoc