URL-encoded form data format
The
urlencodeddata format parsesapplication/x-www-form-urlencodedtext into a map (unmarshal) and writes a map as form text (marshal).
Name: urlencoded · Crate: cameleer-core · Cargo feature: none, always included (build features) · Apache Camel: no direct equivalent (Camel
handles forms in the HTTP components)
When to use it
- Read HTML form posts and webhook callbacks that arrive as
a=1&b=2(Slack slash commands, Twilio, payment providers). - Build the body of an OAuth token request or any form POST.
Marshal and unmarshal
| direction | body in | body out |
|---|---|---|
unmarshal | form text | a map. + and %XX are decoded; a repeated key becomes a list. |
marshal | a map (null gives an empty string) | form text. List values repeat the key. |
Example
Parse a form post and turn it into JSON:
- route:
id: form-to-json
from:
uri: direct:form-to-json
steps:
- unmarshal:
urlencoded: {}
- marshal:
json: {}name=Ada+Lovelace&topic=math&topic=engines¬e=50%25+off{"name":"Ada Lovelace","topic":["math","engines"],"note":"50% off"}Build a form body from JSON, for example for an OAuth client-credentials request:
- route:
id: json-to-form
from:
uri: direct:json-to-form
steps:
- unmarshal:
json: {}
- marshal:
urlencoded: {}{"grant_type":"client_credentials","scope":"read write"}grant_type=client_credentials&scope=read%20writeRust DSL
b.from("direct:urlencoded-rust")
.unmarshal(DataFormatDefinition::urlencoded())
.set_body(simple("${body[name]}"));Options
None.
Common questions
How do I read a form field from a POST body?
unmarshal: {urlencoded: {}}, then ${body[field]} in Simple. Repeated fields are lists.
Are spaces written as + or %20?
marshal writes %20. unmarshal accepts both.
Related
Found a problem?
If something on this page doesn't match what Cameleer does, or you hit a bug while building
with it, please help fix it, whether you are a person or a coding agent:
open an issue that describes what you saw,
then fork the repository, fix it, add or update a test, run cargo test --workspace, and open
a pull request. CONTRIBUTING.md
explains the ground rules.