-
Notifications
You must be signed in to change notification settings - Fork 22
feat(io-ts-http): add all http status codes #418
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,29 +1,131 @@ | ||
| // TODO: Enforce consistency at the type level | ||
|
|
||
| export const HttpToKeyStatus = { | ||
| 100: 'continue', | ||
| 101: 'switchingProtocols', | ||
| 102: 'processing', | ||
| 200: 'ok', | ||
| 201: 'created', | ||
| 202: 'accepted', | ||
| 203: 'nonAuthoritativeInformation', | ||
| 204: 'noContent', | ||
| 205: 'resetContent', | ||
| 206: 'partialContent', | ||
| 207: 'multiStatus', | ||
| 208: 'alreadyReported', | ||
| 226: 'imUsed', | ||
| 300: 'multipleChoices', | ||
| 301: 'movedPermanently', | ||
| 302: 'found', | ||
| 303: 'seeOther', | ||
| 304: 'notModified', | ||
| 307: 'temporaryRedirect', | ||
| 308: 'permanentRedirect', | ||
| 400: 'invalidRequest', | ||
| 401: 'unauthenticated', | ||
| 402: 'paymentRequired', | ||
| 403: 'permissionDenied', | ||
| 404: 'notFound', | ||
| 405: 'methodNotAllowed', | ||
| 406: 'notAcceptable', | ||
| 407: 'proxyAuthenticationRequired', | ||
| 408: 'requestTimeout', | ||
| 409: 'conflict', | ||
| 410: 'gone', | ||
| 411: 'lengthRequired', | ||
| 412: 'preconditionFailed', | ||
| 413: 'contentTooLarge', | ||
| 414: 'uriTooLong', | ||
| 415: 'unsupportedMediaType', | ||
| 416: 'rangeNotSatisfiable', | ||
| 417: 'exceptionFailed', | ||
| 418: 'imATeapot', | ||
| 421: 'misdirectedRequest', | ||
| 422: 'unprocessableContent', | ||
| 423: 'locked', | ||
| 424: 'failedDependency', | ||
| 425: 'tooEarly', | ||
| 426: 'upgradeRequired', | ||
| 428: 'preconditionRequired', | ||
| 429: 'rateLimitExceeded', | ||
| 431: 'requestHeaderFieldsTooLarge', | ||
| 451: 'unavailableForLegalReasons', | ||
| 500: 'internalError', | ||
| 501: 'notImplemented', | ||
| 502: 'badGateway', | ||
| 503: 'serviceUnavailable', | ||
| 504: 'gatewayTimeout', | ||
| 505: 'httpVersionNotSupported', | ||
| 506: 'variantAlsoNegotiates', | ||
| 507: 'insufficientStorage', | ||
| 508: 'loopDetected', | ||
| 510: 'notExtended', | ||
| 511: 'networkAuthenticationRequired', | ||
| } as const; | ||
|
|
||
| export type HttpToKeyStatus = typeof HttpToKeyStatus; | ||
|
|
||
| export const KeyToHttpStatus = { | ||
| continue: 100, | ||
| switchingProtocols: 101, | ||
| processing: 102, | ||
| ok: 200, | ||
| created: 201, | ||
| accepted: 202, | ||
| nonAuthoritativeInformation: 203, | ||
| noContent: 204, | ||
| resetContent: 205, | ||
| partialContent: 206, | ||
| multiStatus: 207, | ||
| alreadyReported: 208, | ||
| imUsed: 226, | ||
| multipleChoices: 300, | ||
| movedPermanently: 301, | ||
| found: 302, | ||
| seeOther: 303, | ||
| notModified: 304, | ||
| temporaryRedirect: 307, | ||
| permanentRedirect: 308, | ||
| invalidRequest: 400, | ||
| unauthenticated: 401, | ||
| paymentRequired: 402, | ||
| permissionDenied: 403, | ||
| notFound: 404, | ||
| methodNotAllowed: 405, | ||
| notAcceptable: 406, | ||
| proxyAuthenticationRequired: 407, | ||
| requestTimeout: 408, | ||
| conflict: 409, | ||
| gone: 410, | ||
| lengthRequired: 411, | ||
| preconditionFailed: 412, | ||
| contentTooLarge: 413, | ||
| uriTooLong: 414, | ||
| unsupportedMediaType: 415, | ||
| rangeNotSatisfiable: 416, | ||
| exceptionFailed: 417, | ||
| imATeapot: 418, | ||
| misdirectedRequest: 421, | ||
| unprocessableContent: 422, | ||
| locked: 423, | ||
| failedDependency: 424, | ||
| tooEarly: 425, | ||
| upgradeRequired: 426, | ||
| preconditionRequired: 428, | ||
| rateLimitExceeded: 429, | ||
| requestHeaderFieldsTooLarge: 431, | ||
| unavailableForLegalReasons: 451, | ||
| internalError: 500, | ||
| notImplemented: 501, | ||
| badGateway: 502, | ||
| serviceUnavailable: 503, | ||
| gatewayTimeout: 504, | ||
| httpVersionNotSupported: 505, | ||
| variantAlsoNegotiates: 506, | ||
| insufficientStorage: 507, | ||
| loopDetected: 508, | ||
| notExtended: 510, | ||
| networkAuthenticationRequired: 511, | ||
| } as const; | ||
|
|
||
| export type KeyToHttpStatus = typeof KeyToHttpStatus; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leaving a quick comment, this thought isn't fully formed/revived:
api-ts was originally conceived to be transport-layer agnostic, so you could use the same service handler but swap out the transport layer. For example, with no changes to business logic you could switch from HTTP to gRPC.
io-ts-http happens to be the HTTP-specific api-ts library. We haven't included any gRPC-specific code yet, but this PR proposes changes that undeniably couple the response library, and api-ts, to HTTP.
I'd love to hear @bitgopatmcl's thoughts!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The motivation here was that we keep having needs for different HTTP status codes popping up, and each time they are added in a one-off slowing down the ticket which needs the new status code. Given that there are a finite number of supported and recognized status codes, I thought it best to add all of them.
I thought this comment seemed a little misplaced as it is the only mention of GRPc in this lib is in this comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any planned net-new development on these libs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do feel like if it is to be transport-layer agnostic, it should have all status codes available to the lib user on HTTP, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just want to support the need for having more status codes
we've defined a bunch of these ourselves but having them in is
io-ts-httpdefinitely makes senseThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe I have already modified that file as part of this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To clarify is this a change request or simply a suggestion for the future? Want to note that this would introduce a breaking change if we were to pull this out of the response lib.
Also, it seems like there are already http statuses which don't map 1-1 with a gRPC status, for example 405 -> NOT_FOUND. Seems like response is already 'coupled' to http in some sense.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels like the response lib should just be called
response-http. And we can have separate response libs for other protocols. This is not a change request. Just a suggestionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, either that or just merge it into
io-ts-http. If we do eventually want to implement other protocols such as gRPC, then services that want to be protocol-agnostic can limit themselves to the intersection of response codes supported by all protocols.This avoids needing to try and anticipate what the set of "generic" responses is, like this library currently does. Even then it only mentions gRPC, if we want to use something else then it could have an entirely different set of responses anyway.
With that in mind I think we can merge this with intent to deprecate the library as a follow-up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, thank you Patrick! I can add a ticket for this if you haven't already done so