Posting a File and Associated Data to a RESTful WebService preferably as JSON

This is probably going to be a stupid question but I’m having one of those nights. In an application I am developing RESTful API and we want the client to send data as JSON. Part of this application requires the client to upload a file (usually an image) as well as information about the image. … Read more

REST HTTP status codes for failed validation or invalid duplicate

I am building an application with a REST-based API and have come to the point where I am specifying status codes for each requests. What status code should i send for requests failing validation or where a request is trying to add a duplicate in my database? I’ve looked through http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html but none of them … Read more

How do you set the Content-Type header for an HttpClient request?

I’m trying to set the Content-Type header of an HttpClient object as required by an API I am calling. I tried setting the Content-Type like below: using (var httpClient = new HttpClient()) { httpClient.BaseAddress = new Uri(“http://example.com/”); httpClient.DefaultRequestHeaders.Add(“Accept”, “application/json”); httpClient.DefaultRequestHeaders.Add(“Content-Type”, “application/json”); // … } It allows me to add the Accept header but when I … Read more

Use of PUT vs PATCH methods in REST API real life scenarios

First of all, some definitions: PUT is defined in Section 9.6 RFC 2616: The PUT method requests that the enclosed entity be stored under the supplied Request-URI. If the Request-URI refers to an already existing resource, the enclosed entity SHOULD be considered as a modified version of the one residing on the origin server. If … Read more

HTTP response code for POST when resource already exists

I’m building a server that allows clients to store objects. Those objects are fully constructed at client side, complete with object IDs that are permanent for the whole lifetime of the object. I have defined the API so that clients can create or modify objects using PUT: PUT /objects/{id} HTTP/1.1 … {json representation of the … Read more

SOAP vs REST (differences)

I have read articles about the differences between SOAP and REST as a web service communication protocol, but I think that the biggest advantages for REST over SOAP are: REST is more dynamic, no need to create and update UDDI(Universal Description, Discovery, and Integration). REST is not restricted to only XML format. RESTful web services … Read more

HTTP GET with request body

I’m developing a new RESTful webservice for our application. When doing a GET on certain entities, clients can request the contents of the entity. If they want to add some parameters (for example sorting a list) they can add these parameters in the query string. Alternatively I want people to be able to specify these … Read more

How do I POST JSON data with cURL?

I use Ubuntu and installed cURL on it. I want to test my Spring REST application with cURL. I wrote my POST code at the Java side. However, I want to test it with cURL. I am trying to post a JSON data. Example data is like this: {“value”:”30″,”type”:”Tip 3″,”targetModule”:”Target 3″,”configurationGroup”:null,”name”:”Configuration Deneme 3″,”description”:null,”identity”:”Configuration Deneme 3″,”version”:0,”systemId”:3,”active”:true} … Read more