/// <summary> /// Handles a POST by creating a resource /// </summary> /// <param name="request"></param> /// <param name="resourceHandler"></param> /// <param name="resourceDescriptor"></param> /// <param name="resource"></param> /// <returns></returns> private async Task HandlePost(IRequest request, IResourceHandler resourceHandler, ResourceDescriptor resourceDescriptor, Resource resource) { // create the resource var result = await resourceHandler.Create(resourceDescriptor, resource); // return the new object rendered as JSON request.Response.WithStatus(HttpStatusCode.OK).WithJsonBody(ResourceSerializer.Serialize(result)); }
public Stream Create(string type, string format, Stream content) { IResourceHandler handler = _registry.GetHandler(type); if (handler == null) { return(ErrorMessage(HttpStatusCode.NotImplemented, String.Format("Create resource version of type {0} not implemented.", type))); } try { var reader = new StreamReader(content); string data = reader.ReadToEnd(); string contentType = GetContentType(WebOperationContext.Current.IncomingRequest.ContentType, format); WebOperationContext.Current.OutgoingResponse.StatusCode = handler.Create(contentType, data); return(new MemoryStream(Encoding.UTF8.GetBytes(String.Empty))); } catch (Exception e) { return(ErrorMessage(HttpStatusCode.InternalServerError, e.Message)); } }