RESTful DELETE with a comment - rest

I have a RESTful API. DELETE /Collection/<Object-ID> will delete the specified object. We don't delete the objects internaly. It will only marked as deleted.
Now it is required to enter a delete comment. How is this possible with REST?

You have many options (as outlined in this question), but none of them are really considered standard practice. I personally would avoid using custom HTTP headers, but then you might run into trouble with certain HTTP implementations disallowing (or even ignoring) request bodies when sending DELETEs.

You can add a custom http header on the request from the client, and then read it from the server.
Edit:
Example for request with custom header:
DELETE /path/to/resource HTTP/1.1
Host: localhost:8080
Accept: */*
Delete-Comment: not needed anymore
Response:
HTTP/1.1 410 Gone
Date: Thu, 14 Nov 2013 13:56:26 GMT
Content-Length: 0
Note that X-Headers are deprecated: Custom HTTP headers : naming conventions

Related

Postman file upload boundary

I'm trying to upload a file with my REST POST request. It is not working out. When i try to look at the request postman give:
Cache-Control: no-cache
Connection: keep-alive
Content-Length: 44262
Content-Type: multipart/form-data; boundary=--------------------------085877645320272030820682
Host: localhost
Why there is a boundry? why postman doesn't return the file that i uploaded?
Adding an attachment as 'binary' would solve the POST request problem in your case.
If you would like to download the same attachment, there should be an GET request towards the API.
If that doesn't solve, you should describe your issue better with some pictures to understand better.

RESTful API POST call request without a body

I want to create a new call in my API that links two already created resources together. Therefore, I don't need to pass any json entities in the post body I just need the resources IDs which I am passing in the URL. Is that a wrong practice? so basically my request now is only a simple path {cid}/projects/{projectID}/subcontractors/{subcontractorID}
and in the post call method I extract the resources IDs from the path and I link them. The response is only either pass or fail {"success":true}. Is that a wrong practice? Is there a better way of doing this?
How you will design your API is really up to you. From a technical point of view, a POST request with an empty payload is completely fine.
However, assuming that you intend to add a contractor to a project, I think it could be better expressed with a payload:
POST /projects/1/contractors HTTP/1.1
Host: api.example.org
Content-Type: application/json
{ "contractorId": 100 }
This approach is specially useful if you need to manage more information for that contractor in that project. If above request succeeds, the response would contain the 201 status code along with a Location header that identifies the newly created resource.
Since you are linking the already existing resources - projects and contractors. I wouldn't prefer the POST method.
Instead I would use the PATCH method (as I am only editing the partial content of the existing resources)
Either the payload or the request URL methods are acceptable.
Request URL:
PATCH /projects/3/contractors/23 HTTP/1.1
HOST example.com/api
Payload
PATCH /projects/3/contractors HTTP/1.1
HOST example.com/api
Content-Type: application/json
{ "contractor_id": 23 }
A successful response is indicated by 200 status code which may contain the payload, or
204 response

REST API cache control for shared cache on server?

I would like to implement some caching on my REST API server so that clients can get faster responses from cached data that is shared among them.
However, I would still like to give clients the option of getting fresh data if they prefer it.
Most examples of the HTTP cache headers I have seen assume that the data is being cached locally on the client, but I will be storing it on my server in Redis.
What is the preferred method to expose cache control functionality to clients when the cache is server-side and shared?
Thank you.
Have you looked at the Cache-Control
Cache-Control: max-age=
Cache-Control: max-stale[=]
Cache-Control: min-fresh=
Cache-Control: no-cache
Cache-Control: no-store
Cache-Control: no-transform
Cache-Control: only-if-cached

Browser doesn't return If-None-Match header

i am trying to implement caching for dynamic API calls where data is near-static. The approach i have taken is using the ETag and returning an ETag header for a Web API response headers. However, Browser doesn't seems to return the "if-None-Match" header at all for me to validate the subsequent calls.
Please note that i am using https and i have a valid SSL installed. Anyone had this issue and potential clues?
Found the root cause of the issue, It was due to the wrong cache-headers being sent by the server particularly Cache-Control: no-store
After changing the response headers, Browser is now able to send the If-None-Match request header.
My current response header is as below which is good enough to request the browser to re-validate it.

Emails not sending when requesting signatures for DocuSign API

I have written the following two methods for sending requests for signatures.
From template: https://github.com/wadewegner/docusign-sample/blob/master/src/DocuSign/DocuSignClient.cs#L215
From binary: https://github.com/wadewegner/docusign-sample/blob/master/src/DocuSign/DocuSignClient.cs#L152
Both work great and I can see they are out for signature:
The trouble is receiving the email requesting the signature is spotty at best. Early on in my testing it seemed I'd (mostly) get the email, but a couple days in and I haven't received any of the emails you see in the image above.
I'm using a developer sandbox. Is there some kind of restriction?
Also, it seems sending to a different email address from the one I registered is particularly problematic. Are there even more restrictions?
Thank you!
Edit: adding additional info requested.
REQUEST #1 (posting document):
POST https://demo.docusign.net/restapi/v2/accounts/892965/envelopes HTTP/1.1
X-DocuSign-Authentication: <DocuSignCredentials>...</DocuSignCredentials>
Accept: application/json
Content-Type: multipart/form-data; boundary="BOUNDARY"
Host: demo.docusign.net
Content-Length: 91206
Expect: 100-continue
--BOUNDARY
Content-Type: application/xml; charset=utf-8
Content-Disposition: form-data
<envelopeDefinition xmlns="http://www.docusign.com/restapi"><emailSubject>DocuSign API - Signature Request on Document</emailSubject><status>sent</status><documents><document><documentId>1</documentId><name>test.pdf</name></document></documents><recipients><signers><signer><recipientId>1</recipientId><email>wade.wegner#gmail.com</email><name>Wade Wegner</name><tabs><signHereTabs><signHere><xPosition>100</xPosition><yPosition>100</yPosition><documentId>1</documentId><pageNumber>1</pageNumber></signHere></signHereTabs></tabs></signer></signers></recipients></envelopeDefinition>
--BOUNDARY
Content-Disposition: form-data; name=test; filename=test.pdf; filename*=utf-8''test.pdf
<truncating binary>
REQUEST #2 (from template):
POST https://demo.docusign.net/restapi/v2/accounts/892965/envelopes HTTP/1.1
X-DocuSign-Authentication: <DocuSignCredentials>...</DocuSignCredentials>
Accept: application/json
Content-Type: application/xml; charset=utf-8
Host: demo.docusign.net
Content-Length: 421
Expect: 100-continue
<envelopeDefinition xmlns="http://www.docusign.com/restapi"><status>sent</status><emailSubject>DocuSign API - Signature Request from Template</emailSubject><templateId>29CB97E5-DCE1-4C14-91A8-A8317BCD29AD</templateId><templateRoles><templateRole><name>Wade Wegner</name><email>wade.wegner#gmail.com</email><roleName>Signing Role</roleName><clientUserId>1</clientUserId></templateRole></templateRoles></envelopeDefinition>
The ClientUserId causes a recipient to be an embedded recipient. If you provide a value then DocuSign will not send emails. The expectation is that you are going to handle the communication with the signer. This allows you to embed the signing experience within your own website or application.
I think without a trace of your JSON it's hard to figure out where the problems are. One problem could be that you create the envelope in the "created" instead of "sent" state. Another problem could be that you are providing a "clientUserId" which signals to our system that you are embedding the signing experience.
Why don't you get the status on the envelopes where you think you didn't get the e-mail and see what it looks like.
-mb