restgrailsgrails-4grails-rest-api

Property of class cannot be null error when making curl POST request to REST api in Grails 4


I created a new Grails 4.0.10 app using rest application profile. I would like to check how the Resource annotation works. According to the docs, if I annotate Resource on domain then I don't need to write a controller.

The domain I have is:

package book
import grails.rest.Resource
@Resource(uri='/books', formats=['json', 'xml'])
class Book {
    String title
    static constraints = {
    }
}

I run the app. When I run this curl command to create a book:

`curl -i -X POST -H "Content-Type: application/json" -d '{"title":"Along Came A Spider"}'` localhost:8080/books

I get the following error:

enter image description here

What am I doing wrong?


Solution

  • This is strange

    but i tried in windows cmd prompt

    curl -i -X POST -H "Content-Type: application/json" -d '{"title":"Along Came A Spider"}' localhost:8080/books
    

    it thows error

    but when i tried in Git Bash

    curl -i -X POST -H "Content-Type: application/json" -d '{"title":"Along Came A Spider"}' localhost:8080/books
    

    it succeeds