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

x/website: Error of "Developing a RESTful API with Go and Gin" chapter #47941

Open
tzzs opened this issue Aug 24, 2021 · 2 comments
Open

x/website: Error of "Developing a RESTful API with Go and Gin" chapter #47941

tzzs opened this issue Aug 24, 2021 · 2 comments

Comments

@tzzs
Copy link

@tzzs tzzs commented Aug 24, 2021

What version of Go are you using (go version)?

$ go version
go version go1.16.6 windows/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GOHOSTARCH=amd64
set GOHOSTOS=windows

What did you do?

I wrote a RESTful API for adding albums according to the documentation(Tutorial: Developing a RESTful API with Go and Gin), but when i called it according to the curl command in the case, an error occurred.

$ curl http://localhost:8080/albums \
    --include \
    --header "Content-Type: application/json" \
    --request "POST" \
    --data '{"id": "4","title": "The Modern Sound of Betty Carter","artist": "Betty Carter","price": 49.99}'

Finall I found out that I need to escape the double quotes in the data send using curl, otherwise the problem will occur.
The following case can be send successfully.

curl http://localhost:8080/albums --include --header "Content-Type: application/json" --request "POST" --data '{\"id\": \"4\",\"title\": \"The Modern Sound of Betty Carter\",\"artist\": \"Betty Carter\",\"price\": 49.99}'

What did you expect to see?

curl http://localhost:8080/albums --include --header "Content-Type: application/json" --request "POST" --data '{\"id\": \"4\",\"title\": \"The Modern Sound of Betty Carter\",\"artist\": \"Betty Carter\",\"price\": 49.99}'

What did you see instead?

$ curl http://localhost:8080/albums \
    --include \
    --header "Content-Type: application/json" \
    --request "POST" \
    --data '{"id": "4","title": "The Modern Sound of Betty Carter","artist": "Betty Carter","price": 49.
@gopherbot gopherbot added this to the Unreleased milestone Aug 24, 2021
@seankhliao
Copy link
Contributor

@seankhliao seankhliao commented Aug 24, 2021

which shell is this? In sh-like shells the outer single quotes mean the inside double quotes don't need to be escaped

Loading

@tzzs
Copy link
Author

@tzzs tzzs commented Aug 26, 2021

which shell is this? In sh-like shells the outer single quotes mean the inside double quotes don't need to be escaped

I have this problem with CMD and new Powershell 7.1.4, which I often use on windows.

Loading

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants