Announcement Announcement Module
Collapse
No announcement yet.
Spring Data REST 1.0.0.M2 - How do you POST to create a new entity? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring Data REST 1.0.0.M2 - How do you POST to create a new entity?

    What do we POST to create a new Person entity in the example that
    comes with the JPA Exporter?
    I tried POSTing to http://localhost:8080/data/people, but no dice.



    Details of failing POST are below:

    Request URL:http://localhost:8080/data/people
    Request Method:POST
    Status Code:406 Not Acceptable
    Request Headersview source
    Accept:application/json
    Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3
    Accept-Encoding:gzip,deflate,sdch
    Accept-Language:en-US,en;q=0.8
    Connection:keep-alive
    Content-Length:11
    Content-Type:application/x-www-form-urlencoded
    Cookie:JSESSIONID=06008EC6784AEEF8D49F4DB1E8E5A81B
    Host:localhost:8080
    Origin:chrome-extension://hgmloofddffdnphfgcellkdfbfbjeloo
    User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.11 (KHTML, like Gecko) Chrome/20.0.1132.11 Safari/536.11
    Form Dataview URL encoded
    name:foobar
    Response Headersview source
    Content-Language:en-US
    Content-Length:0
    Content-Type:application/json; charset=ISO-8859-1
    Server:Jetty(6.1.25)

  • #2
    I too, am having problems, in 1.0.0 RC1. I try posting as such:

    curl -v -d '{"name" : "John Doe"}' -H "Content-Type: application/json" http://localhost:8080/data/people

    response is:

    * About to connect() to localhost port 8080 (#0)
    * Trying 127.0.0.1...
    * connected
    * Connected to localhost (127.0.0.1) port 8080 (#0)
    > POST /data/people HTTP/1.1
    > User-Agent: curl/7.26.0
    > Host: localhost:8080
    > Accept: */*
    > Content-Type: application/json
    > Content-Length: 6
    >
    * upload completely sent off: 6 out of 6 bytes
    < HTTP/1.1 400 Bad Request
    < Content-Type: text/html; charset=iso-8859-1
    < Cache-Control: must-revalidate,no-cache,no-store
    < Content-Length: 1380
    < Server: Jetty(6.1.25)
    <
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
    <title>Error 400 BAD_REQUEST</title>
    </head>
    <body><h2>HTTP ERROR 400</h2>
    <p>Problem accessing /data/people. Reason:
    <pre> BAD_REQUEST</pre></p><hr /><i><small>Powered by Jetty://</small></i><br/>
    </body>
    </html>
    * Connection #0 to host localhost left intact
    * Closing connection #0

    Comment


    • #3
      I found my problem was with my quoting was inappropriate for Windows command line. I had to use:

      curl -v -X POST -d "{\"name\":\"John Doe\"}" -H "Content-Type: application/json" http://localhost:8080/spring-data-rest/people

      And then it worked. Yowsa, spent several hours figuring that out.

      Comment

      Working...
      X