Genie.Requests.jsonpayload — Function
jsonpayload()Processes an application/json POST request. If it fails to successfully parse the JSON data it returns nothing. The original payload can still be accessed invoking rawpayload()
jsonpayload(v)Processes an application/json POST request attempting to return value corresponding to key v.
Genie.Requests.rawpayload — Function
rawpayload() :: StringReturns the raw POST payload as a String.
Genie.Requests.filespayload — Function
filespayload() :: Dict{String,HttpFile}Collection of form uploaded files.
filespayload(filename::Union{String,Symbol}) :: HttpFileReturns the HttpFile uploaded through the key input name.
Genie.Requests.infilespayload — Function
infilespayload(key::Union{String,Symbol}) :: BoolChecks if the collection of uploaded files contains a file stored under the key name.
Base.write — Function
write(io::IO, x)Write the canonical binary representation of a value to the given I/O stream or file. Return the number of bytes written into the stream. See also print to write a text representation (with an encoding that may depend upon io).
The endianness of the written value depends on the endianness of the host system. Convert to/from a fixed endianness when writing/reading (e.g. using htol and ltoh) to get results that are consistent across platforms.
You can write multiple values with the same write call, i.e. the following are equivalent:
write(io, x, y...)
write(io, x) + write(io, y...)Examples
Consistent serialization:
julia> fname = tempname(); # random temporary filename
julia> open(fname,"w") do f
# Make sure we write 64bit integer in little-endian byte order
write(f,htol(Int64(42)))
end
8
julia> open(fname,"r") do f
# Convert back to host byte order and host integer type
Int(ltoh(read(f,Int64)))
end
42Merging write calls:
julia> io = IOBuffer();
julia> write(io, "JuliaLang is a GitHub organization.", " It has many members.")
56
julia> String(take!(io))
"JuliaLang is a GitHub organization. It has many members."
julia> write(io, "Sometimes those members") + write(io, " write documentation.")
44
julia> String(take!(io))
"Sometimes those members write documentation."User-defined plain-data types without write methods can be written when wrapped in a Ref:
julia> struct MyStruct; x::Float64; end
julia> io = IOBuffer()
IOBuffer(data=UInt8[...], readable=true, writable=true, seekable=true, append=false, size=0, maxsize=Inf, ptr=1, mark=-1)
julia> write(io, Ref(MyStruct(42.0)))
8
julia> seekstart(io); read!(io, Ref(MyStruct(NaN)))
Base.RefValue{MyStruct}(MyStruct(42.0))Base.read — Function
read(command::Cmd, String)Run command and return the resulting output as a String.
read(command::Cmd)Run command and return the resulting output as an array of bytes.
read(s::IOStream, nb::Integer; all=true)Read at most nb bytes from s, returning a Vector{UInt8} of the bytes read.
If all is true (the default), this function will block repeatedly trying to read all requested bytes, until an error or end-of-file occurs. If all is false, at most one read call is performed, and the amount of data returned is device-dependent. Note that not all stream types support the all option.
read(s::IO, nb=typemax(Int))Read at most nb bytes from s, returning a Vector{UInt8} of the bytes read.
read(filename::AbstractString)Read the entire contents of a file as a Vector{UInt8}.
read(filename::AbstractString, String)Read the entire contents of a file as a string.
read(filename::AbstractString, args...)Open a file and read its contents. args is passed to read: this is equivalent to open(io->read(io, args...), filename).
read(io::IO, T)Read a single value of type T from io, in canonical binary representation.
Note that Julia does not convert the endianness for you. Use ntoh or ltoh for this purpose.
read(io::IO, String)Read the entirety of io, as a String (see also readchomp).
Examples
julia> io = IOBuffer("JuliaLang is a GitHub organization");
julia> read(io, Char)
'J': ASCII/Unicode U+004A (category Lu: Letter, uppercase)
julia> io = IOBuffer("JuliaLang is a GitHub organization");
julia> read(io, String)
"JuliaLang is a GitHub organization"read(conn, nb::Integer; all::Bool=true) -> Vector{UInt8}Read and return up to nb bytes from conn.
If all is true (the default), the call keeps reading until nb bytes have been transferred, EOF is reached, or an error occurs. If all is false, at most one underlying socket read is performed.
read(conn, nb::Integer; all::Bool=true) -> Vector{UInt8}Read and return up to nb decrypted bytes from conn.
If all is true (the default), the call keeps reading until nb bytes have been transferred, EOF is reached, or an error occurs. If all is false, at most one underlying TLS read is performed.
read(stream::IO, [nb::Integer,] enc::Encoding)
read(filename::AbstractString, [nb::Integer,] enc::Encoding)
read(stream::IO, ::Type{String}, enc::Encoding)
read(filename::AbstractString, ::Type{String}, enc::Encoding)Methods to read text in character encoding enc. See documentation for corresponding methods without the enc argument for details.
read(file::HttpFile)Returns the content of file as string.
Genie.Requests.filename — Function
filename(file::HttpFile) :: StringOriginal filename of the uploaded HttpFile file.
Genie.Requests.postpayload — Function
postpayload() :: Dict{Symbol,Any}A dict representing the POST variables payload of the request (corresponding to a form-data request)
postpayload(key::Symbol) :: AnyReturns the value of the POST variables key.
postpayload(key::Symbol, default::Any)Returns the value of the POST variables key or the default value if key is not defined.
Genie.Requests.getpayload — Function
getpayload() :: Dict{Symbol,Any}A dict representing the GET/query variables payload of the request (the part corresponding to ?foo=bar&baz=moo)
getpayload(key::Symbol) :: AnyThe value of the GET/query variable key, as in ?key=value
getpayload(key::Symbol, default::Any) :: AnyThe value of the GET/query variable key, as in ?key=value. If key is not defined, default is returned.
Genie.Requests.request — Function
request() :: HTTP.RequestReturns the raw HTTP.Request object associated with the request. If no request is available (not within a request/response cycle) returns nothing.
Genie.Requests.payload — Function
payload() :: AnyUtility function for accessing the params collection, which holds the request variables.
payload(key::Symbol) :: AnyUtility function for accessing the key value within the params collection of request variables.
payload(key::Symbol, default_value::T) :: AnyUtility function for accessing the key value within the params collection of request variables. If key is not defined, default_value is returned.
Genie.Requests.matchedroute — Function
matchedroute() :: RouteReturns the Route object which was matched for the current request or noting if no route is available.
Genie.Requests.matchedchannel — Function
matchedchannel() :: ChannelReturns the Channel object which was matched for the current request or nothing if no channel is available.
Genie.Requests.wsclient — Function
wsclient() :: HTTP.WebSockets.WebSocketThe web sockets client for the current request or nothing if not available.