Results 1 to 3 of 3

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

  1. #1
    Join Date
    Jul 2006
    Location
    Houston, TX
    Posts
    80

    Question 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. #2
    Join Date
    Jul 2012
    Posts
    4

    Default

    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

  3. #3
    Join Date
    Jul 2012
    Posts
    4

    Default

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •