Jul 11, 2013

Use CURL to test POST RESTful API

I was working one specific task about RESTful API and it took me sometime, and after finish it I think it's worth sharing.

The task is: I need to implement a POST RESTful API, which accepts multiple parameters. And I will make it be able to call by a C++ or shell script.

The API looks like this, and in JAVA codes:


@POST
@Path("updatecache")
public void postCache(@QueryParam("instanceID") String instanceID, @QueryParam("startTime") String startTime, @QueryParam("endTime") String endTime) {
        /*The implementation details are hidden herer*/
}

To test it in POSTMAN

To test it in CURL, it took me really a long time, and

curl -H "user:abc" -H "password:abc" -X POST "http://localhost:8080/dsm/resources/heatmap/updatecache?instanceID=96&startTime=2013-06-29%2000:00:00&endTime=2013-07-02%2010:00:00"

Note: the URL should be double quoted. Because Typing & in the command line means run the preceding command in the background , because of this anything after the & is being treated as a new command.

If you think this article is useful, please click the ads on this page to help. Thank you very much.

No comments: