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

jsonapi.MarshalPayload sets response status to 200, but I want 201 (created) #218

Open
gabbottron opened this issue Mar 20, 2023 · 1 comment

Comments

@gabbottron
Copy link

I am using jsonapi with gin in a go project. In my create handlers I need to marshal the response and send it back, but the function sets the response code to 200 automagically and I want 201. Gin will not let me override the 200 response after this code block runs. Could you allow for a custom response code on this function if you insist on setting headers?

Thanks!
-Geoff

@crodwell
Copy link

crodwell commented Nov 2, 2023

it's literally in the readme:

w.Header().Set("Content-Type", jsonapi.MediaType)
w.WriteHeader(http.StatusCreated)

if err := jsonapi.MarshalPayload(w, blog); err != nil {
	http.Error(w, err.Error(), http.StatusInternalServerError)
}

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

No branches or pull requests

2 participants