We are currently in the process of wrangling smaller services from our monoliths. Our domain is very similar to a ticketing system. We have decided to start with the cancellation process of the domain.
Our cancel service has as simple endpoint "Cancel" which takes in the id of the ticket. Internally, we retrieve the id, perform some operations related to cancel on it and update the state of the entity in the store. From the store's perspective the only difference between a cancelled ticket and a live ticket are a few properties.
From what I have read, PATCH seems to be the correct verb to be used in this case, as am updating only a simple property in the resource.
PATCH /api/tickets/{id}
Payload {isCancelled: true}
But isCancelled is not an actual property in the entity. Is it fair to send properties in the payload that are not part of the entity or should I think of some other form of modeling this request? I would not want to send the entire entity as part of the payload, since it is large.
I have considered creating a new resource CancelledTickets, but in our domain we would never have the need to a GET on cancelled tickets. Hence stayed away from having to create a new resource.
Firstly you need to use multiple threads because your program will be on hold while it is sending the request so you cannot click on something until it is back from hold. Create a thread which calls the rest API in background without hanging the overall application and terminate that thread on click of a button.
The Cancel Request API allows any data task or HTTP request to be cancelled.
If you are using REST, then it means you can never cancel the API call. If it gets submitted, it will continue processing in the backend even if you stop it in the frontend. But if 'Cancelling' is much important for your application through the API call, then you must consider other alternatives, like SOAP or RPC.
We can use the AbortController object and the associated AbortSignal with the Fetch API to make cancelable HTTP requests. Once the AbortSignal is sent, the HTTP request is canceled and won't be sent if the cancellation signal is sent before the HTTP request is done.
Take a look what exactly is RESTful way. No matter if you send PATCH
request with isCancelled
as payload or even DELETE
if you want tickets to disappear. It's still RESTful.
Your move depends on your needs. As you said
I have considered creating a new resource CancelledTickets, but in our domain we would never have the need to a GET on cancelled tickets.
I would just send DELETE
. You don't have to remove it physically. If it's possible to un-cancel, then implement isCancelled
mechanism. It's just question of taste.
Exposing the GET
interface of a resource is not compulsory.
For example, use
PUT /api/tickets/{id}/actions/cancel
to submit the cancellation request. I choose PUT
since there would be no more than one cancellation request in effect.
Hope it be helpful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With