Skip to content

Alternate long running operation strategy #101

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: vNext
Choose a base branch
from

Conversation

darrelmiller
Copy link
Member

Related to #10

This change removes the need for the custom header Operation-Location and uses the standard Content-Location header to enable the hybrid flow. This approach ensures that all long running operations use the standard 202 status code and Location header pattern. It also removes the need to prevent a body from being returned with a 202 response.

@darrelmiller darrelmiller changed the title Alternate Long running operation strategy Alternate long running operation strategy Feb 6, 2018
@markdstafford markdstafford self-requested a review February 13, 2018 19:44
Copy link

@markdstafford markdstafford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me overall. Should we elaborate more about the responsibilities of the Location and Content-Location headers?

Copy link
Contributor

@cleemullins cleemullins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree the changes here are probably slightly cleaner. However, in the case I would opt for stabilty-as-a-feature and avoid the churn this breaking change would cause.

@@ -1360,7 +1357,7 @@ POST https://api.contoso.com/v1.0/databases/

```http
HTTP/1.1 202 Accepted
Operation-Location: https://api.contoso.com/v1.0/operations/123
Location: https://api.contoso.com/v1.0/operations/123
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change. While I like the use of a standard header here, I don't think it meets the bar for a breaking change. Stability is a feature, in and of itself.

I know we considered the location header at the time we wrote these, but I don't recall why it was rejected.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this part of why we adopted semantic versioning for the guidelines? Putting stability as the guiding priority means that we will grind forward progress to a halt. This is a positive change in the guidelines. It warrants a bump to version 3. As before, APIs are not required to make breaking changes just so they can adopt the new guidelines - but for new APIs, wouldn't we want the right baseline in place?

In my opinion, we should be putting additive changes into 2.x of the API guidelines, but not unnecessarily blocking a 3.x of the guidelines from being created. We could say that we haven't gathered sufficient breaking changes to warrant a 3.x at this point, but then I would ask where we plan to track those changes, and whether we can start on 3.x-preview1 even if we choose not to release 3.x until we do get to critical mass.


The 202 Accepted should return no body.
The 201 Created case should return the body of the target resource.
For services that need to return a partially created response here, use the hybrid flow described below.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the words here.

```

For services that need to return a 201 Created here, use the hybrid flow described below.

The 202 Accepted should return no body.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These requirements seem important. Not clear why they are removed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR proposes that a 202 also be used for the hybrid flow and during that scenario a partially created response is returned. Therefore saying that a body should not be returned with a 202 would be contradictory.

HTTP/1.1 201 Created
Location: https://api.contoso.com/v1.0/databases/db1
Operation-Location: https://api.contoso.com/v1.0/operations/123
HTTP/1.1 202 Accepted
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change.

Location: https://api.contoso.com/v1.0/databases/db1
Operation-Location: https://api.contoso.com/v1.0/operations/123
HTTP/1.1 202 Accepted
Content-Location: https://api.contoso.com/v1.0/databases/db1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually scarier than a breaking change. You're changing the meaning of the location header, which means developers that aren't paying attention will be actively doing the wrong thing. The interaction of old+new code will be very unpredictable here.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, @darrelmiller is not changing the meaning of the Location header. He's pointing out that 201 Created is a misnomer when we are talking about asynchronous resource creation. A strict interpretation of HTTP would lead one to believe that the resource is done being created. In reality, the create request has been 202 Accepted, in which case the usage of Content-Location is additive to the examples we had before.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The meaning of Location header is dependent on the response code. A 202 response code means the Location header points at the status monitor resource (what we call operation). A 201 status code means the Location points to the created resource. For 3xx status codes Location means something else.

Therefore because I'm also changing the status code that is returned for a hybrid flow, the meaning of Location header would be consistently the same as what Operation-Location currently means. Old client code talking to a new API would be missing the Operation-Location header in a 202 response and new client code talking to an old service would see a 201 created and not be aware that it is a hybrid flow LRO.

@@ -1491,7 +1488,7 @@ Services MAY choose to delete tombstones after a service defined period of time.
#### 13.2.7 The typical flow, polling
- Client invokes a stepwise operation by invoking an action using POST
- The server MUST indicate the request has been started by responding with a 202 Accepted status code. The response SHOULD include the location header containing a URL that the client should poll for the results after waiting the number of seconds specified in the Retry-After header.
- Client polls the location until receiving a 200 OK response from the server.
- Client polls the location until receiving a response that indicates the stepwise long running operation is complete.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the words here.

@AkJo
Copy link

AkJo commented Mar 20, 2018

Do we have any consensus on this? We are building a new API and were wondering if we should follow this new approach.

@glennblock
Copy link
Contributor

glennblock commented Mar 25, 2018

If there's concern on a breaking change, why not introduce a header or some way for clients to opt-in to the alternative behavior? The approach suggested seems like it is in-line with how the HTTP spec defines using the 202 header. On a different note, did anyone consider submitting the new header to the IETF, in order to get some discussion around its introduction?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants