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

Need a way to return 201 Created as the result of a PUT #189

Closed
Porges opened this issue Aug 12, 2015 · 7 comments
Closed

Need a way to return 201 Created as the result of a PUT #189

Porges opened this issue Aug 12, 2015 · 7 comments

Comments

@Porges
Copy link

Porges commented Aug 12, 2015

Per RFC7321:

If the target resource does not have a current representation and the
PUT successfully creates one, then the origin server MUST inform the
user agent by sending a 201 (Created) response. If the target
resource does have a current representation and that representation
is successfully modified in accordance with the state of the enclosed
representation, then the origin server MUST send either a 200 (OK) or
a 204 (No Content) response to indicate successful completion of the
request.

At the moment 200 OK (or 204 No Content) is always returned. It would be nice to have a way to indicate that a resource was created.

@jkarni
Copy link
Member

jkarni commented Dec 25, 2015

Closing this as a duplicate of #190 . For people who might come across is, currently the suggested way about it is defining your own combinator, with a HasServer instance that differs from the current one only in having 201 rather than 200 as the status code.

@jkarni jkarni closed this as completed Dec 25, 2015
@i-am-the-slime
Copy link

I tried to backtrack to the actual solution but couldn't really find anything. Can you go into more detail about this "own combinator" approach? Thanks!

@alpmestan
Copy link
Contributor

@i-am-the-slime Hi! This PR changed all existing HTTP method combinators to be simple type synonyms of Verb with different parameters. You can use this to define your own Post that returns something else than 200 by defining a new type synonym similar to servant's default Post but specifying another status code than 200. You need servant from git for now though to be able to use that as this will only be part of the next release.

@i-am-the-slime
Copy link

Ah, I'm using stack. I'll probably wait for the next LTS including this then and just return a 200 in any case.

@alpmestan
Copy link
Contributor

You can use packages from git repos with stack as well, FWIW: http://docs.haskellstack.org/en/stable/yaml_configuration/ (scroll down a bit and look for "git")

@rvion
Copy link
Contributor

rvion commented Mar 15, 2016

eg:

resolver: lts-5.5

# Local packages, usually specified by relative directory name
packages:
- .
- location:
    git: git@github.com:haskell-servant/servant.git
    commit: 5188e842a9288ac3986b30b93cb1a5d58cb2933d
  extra-dep: true
  subdirs:
  - servant
  - servant-blaze
  - servant-cassava
  - servant-client
  - servant-docs
  - servant-examples
  - servant-foreign
  - servant-js
  - servant-lucid
  - servant-mock
  - servant-server

@LeifW
Copy link
Contributor

LeifW commented Apr 12, 2018

I don't see how hardcoding a response code into the type signature addresses the issue, which quotes the RFC as saying either a 201 or 204 should be returned, depending on if the update target already exists.

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

6 participants