Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transport for application/x-www-form-urlencoded content type #2611

Merged
merged 3 commits into from
Apr 8, 2023

Conversation

RatkoR
Copy link
Contributor

@RatkoR RatkoR commented Apr 7, 2023

This is one more (and the last) transport that we're missing in stock gqlgen (I'm done with transports after this PR).

It works with application/x-www-form-urlencoded transports that a big part of out clients use. It is similar to both multipart and graphql transports, but I still decided to do a separate file. Anyone interested in it can enable it in server config, so it's backwards compatible, it wont break anything.

Tests and doc changes are also part of this PR.

transport_form.go is renamed to transport_form_multipart.go as we now have two form transports (transport_form_multipart.go and transport_form_urlencoded.go).

Comments are welcome.

I have:

  • Added tests covering the bug / feature (see testing)
  • Updated any relevant documentation (see docs)

There are multiple ways form data can be encoded. 'multipart' is
just one of them - there are also 'application/x-www-form-urlencoded'
(which will be added in next commit) and 'text/plain' encodings.

Let each encoding have it's own form_xxxx file and tests.
This commit adds transport that handles form POST with content
type set to 'application/x-www-form-urlencoded'.

Form body can be json, urlencoded parameters or plain text.

Example:

```
 curl -X POST 'http://server/query' -d '{name}' -H "Content-Type: application/x-www-form-urlencoded"
```

Enable it in your GQL server with:

```
srv.AddTransport(transport.UrlEncodedForm{})
```
@coveralls
Copy link

coveralls commented Apr 7, 2023

Coverage Status

Coverage: 78.497% (+3.3%) from 75.171% when pulling 7f8b3a6 on RatkoR:transport_form_urlencoded into 4548815 on 99designs:master.

No other changes but this rewrite to switch.
@StevenACoffman
Copy link
Collaborator

Thanks!

@StevenACoffman StevenACoffman merged commit 50c2829 into 99designs:master Apr 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants