Skip to content
This repository has been archived by the owner on Mar 2, 2021. It is now read-only.

Echo json and form data from body #3

Merged
merged 1 commit into from
Dec 11, 2018

Conversation

justinmchase
Copy link
Contributor

This fixes #2

This change parses the body so it is available to echo back using the standard express package body-parser.

NOTE: I manually "prettified" the json output below so it was easier to read.

Before

Notice the lack of "body" in the output:

$ curl -X PUT -H "Content-Type: application/json" -d '{"hello":"world"}' http://localhost:3000
{
	"fresh": false,
	"headers": {
		"accept": "*/*",
		"content-length": "17",
		"content-type": "application/json",
		"host": "localhost:3000",
		"user-agent": "curl/7.54.0"
	},
	"hostname": "localhost",
	"ip": "::1",
	"ips": [],
	"method": "PUT",
	"path": "/",
	"protocol": "http",
	"query": {},
	"subdomains": [],
	"xhr": false
}

After

Notice the presence of "body":{"hello":"world"} in the output now:

json

$ curl -X PUT -H "Content-Type: application/json" -d '{"hello":"world"}' http://localhost:3000
{
	"body": {
		"hello": "world"
	},
	"fresh": false,
	"headers": {
		"accept": "*/*",
		"content-length": "17",
		"content-type": "application/json",
		"host": "localhost:3000",
		"user-agent": "curl/7.54.0"
	},
	"hostname": "localhost",
	"ip": "::1",
	"ips": [],
	"method": "PUT",
	"path": "/",
	"protocol": "http",
	"query": {},
	"subdomains": [],
	"xhr": false
}

form-data

$ curl -X PUT -d hello=world http://localhost:3000
{
	"body": {
		"hello": "world"
	},
	"fresh": false,
	"headers": {
		"accept": "*/*",
		"content-length": "11",
		"content-type": "application/x-www-form-urlencoded",
		"host": "localhost:3000",
		"user-agent": "curl/7.54.0"
	},
	"hostname": "localhost",
	"ip": "::1",
	"ips": [],
	"method": "PUT",
	"path": "/",
	"protocol": "http",
	"query": {},
	"subdomains": [],
	"xhr": false
}

@justinmchase
Copy link
Contributor Author

@ryaninvents ping! 🔔

@ryaninvents ryaninvents merged commit 78d97b6 into kennship:master Dec 11, 2018
@ryaninvents
Copy link
Contributor

@justinmchase Thanks for the contribution! 🎉

@justinmchase justinmchase deleted the fix/echo-body-fixes-2 branch December 11, 2018 21:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Body is not printed out
2 participants