-
Notifications
You must be signed in to change notification settings - Fork 271
According to Spec
Put is used for.
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 the Request-URI does not point to an existing resource, and that URI is capable of being defined as a new resource by the requesting user agent, the origin server can create the resource with that URI. If a new resource is created, the origin server MUST inform the user agent via the 201 (Created) response. If an existing resource is modified, either the 200 (OK) or 204 (No Content) response codes SHOULD be sent to indicate successful completion of the request. If the resource could not be created or modified with the Request-URI, an appropriate error response SHOULD be given that reflects the nature of the problem. The recipient of the entity MUST NOT ignore any Content-* (e.g. Content-Range) headers that it does not understand or implement and MUST return a 501 (Not Implemented) response in such cases.
You can put a service using the Putmethod and using static, anonymous or dynamic objects.
Lets take our Tree as an example.
Our tree object looks like this.
public class Tree
{
public int Id { get; set ; }
public string Genus { get; set; }
}
Now we can put object to our service like this.
var tree = new Tree();
tree.Id = 1;
tree.Genus = "Fagus";
var http = new HttpClient();
http.Put("url", tree, HttpContentTypes.ApplicationJson);
Or we can do it with an anonymous object like this.
var http = new HttpClient();
http.Put("url", new{Id=1, Genus="Fagus"}, HttpContentTypes.ApplicationJson);
or you can Put a dynamic type.
var tree = new ExpandoObject();
tree.Id = 1;
tree.Genus = "Fagus";
var http = new HttpClient();
http.Put("url", tree, HttpContentTypes.ApplicationJson);
You can choose the contenttype.
You can also upload a file with the PutFile method.