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 · 3 comments
Open

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

tzzs opened this issue Aug 24, 2021 · 3 comments
Labels
Documentation NeedsFix The path to resolution is known, but the work has not been done. website

Comments

@tzzs
Copy link

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
Member

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

@tzzs
Copy link
Author

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.

@cherrymui cherrymui added the NeedsFix The path to resolution is known, but the work has not been done. label Aug 30, 2021
@suzmue suzmue modified the milestones: Unreleased, website/unplanned Jun 15, 2022
@Elliott-Hu
Copy link

Elliott-Hu commented Jun 16, 2022

the price must be string in JSON
try it

$ 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"}'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Documentation NeedsFix The path to resolution is known, but the work has not been done. website
Projects
None yet
Development

No branches or pull requests

7 participants