Nex.Req
(nex_core v0.4.3)
Copy Markdown
Standardized Request object for API handlers.
Normalizes incoming requests toward Next.js Pages Router API Route semantics while keeping Nex-specific additions available for framework internals.
Next.js Standard Fields
query- Path params + query string params (Next.jsreq.query)body- Request body params (Next.jsreq.body)headers- Request headers as a Mapcookies- Request cookies as a Mapmethod- HTTP method (uppercase string)
Parameter Merging Behavior
Like Next.js, req.query contains both dynamic path parameters and query string parameters.
When the same key appears in both, path parameters take precedence.
For example, GET /api/users/123?id=456:
req.query["id"]→"123"(path parameter wins)
req.body is completely independent and never merged with req.query.
Examples
# GET /api/users/[id]?page=2
def get(req) do
user_id = req.query["id"] # From path parameter [id]
page = req.query["page"] # From query string
Nex.json(%{user_id: user_id, page: page})
end
# POST /api/users
def post(req) do
name = req.body["name"]
email = req.body["email"]
Nex.json(%{message: "User created"}, status: 201)
endComparison with Next.js
| Next.js | Nex | Notes |
|---|---|---|
req.query | req.query | Same merged path + query semantics |
req.body | req.body | nil when the request has no body params |
req.headers | req.headers | Same access pattern |
req.cookies | req.cookies | Same access pattern |
req.method | req.method | Same uppercase method string |
Summary
Functions
Constructs a Nex.Req from a Plug.Conn.
Types
@type method() :: :get | :post | :put | :patch | :delete | :head | :options
Functions
@spec from_plug_conn(Plug.Conn.t(), params()) :: t()
Constructs a Nex.Req from a Plug.Conn.
This function normalizes the Plug.Conn into a Next.js-compatible request object.