Skip to content
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

feat(http/unstable): add support for multiple request methods on route #6003

Merged

Conversation

LitoMore
Copy link
Contributor

@LitoMore LitoMore commented Sep 17, 2024

This is an approach for #5993 (comment).

It allows the method option to accept a string | string[] value type. It's more convenient for some similar handlers.

Here are some examples:

const route: Route[] = [
	{
		method: ["GET", "HEAD"],
		pattern: new URLPattern({ pathname: '/status' }),
		handler: (req: Request) => new Response(req.method === 'HEAD' ? null : 'ok'),
	},
]
const route: Route[] = [
	{
		method: ["POST", "UPDATE", "DELETE", ...somethingElse],
		pattern: new URLPattern({ pathname: '/users/:id' }),
		handler: (req: Request) => {
			prepareSomething();
			switch (req.method) {
				case "POST":
					createUser();
					break;
				case "UPDATE":
					updateUser();
					break;
				case "DELETE":
					deleteUser();
					break;
				default:
					runSomethingElse();
					break;
			}
			const result = getConclusion();
			return new Response(result);
		},
	},
]

Closes #5993

@LitoMore LitoMore requested a review from kt3k as a code owner September 17, 2024 13:59
@CLAassistant
Copy link

CLAassistant commented Sep 17, 2024

CLA assistant check
All committers have signed the CLA.

@github-actions github-actions bot added the http label Sep 17, 2024
Copy link

codecov bot commented Sep 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 96.28%. Comparing base (3b51807) to head (13a90f3).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6003      +/-   ##
==========================================
- Coverage   96.29%   96.28%   -0.01%     
==========================================
  Files         493      493              
  Lines       39528    39533       +5     
  Branches     5833     5837       +4     
==========================================
+ Hits        38063    38065       +2     
- Misses       1423     1426       +3     
  Partials       42       42              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@LitoMore LitoMore changed the title feat(http): add support multiple request methods on route feat(http): add support for multiple request methods on route Sep 17, 2024
@kt3k kt3k changed the title feat(http): add support for multiple request methods on route feat(http/unstable): add support for multiple request methods on route Sep 18, 2024
Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

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

Thanks for the PR. This makes sense to me. LGTM

@kt3k
Copy link
Member

kt3k commented Sep 18, 2024

Does anyone have any concern to this addition?

Copy link
Collaborator

@iuioiua iuioiua left a comment

Choose a reason for hiding this comment

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

Actually, this seems fine. Thank you.

@iuioiua iuioiua merged commit e1c8d24 into denoland:main Sep 18, 2024
18 checks passed
@LitoMore LitoMore deleted the add-support-for-multiple-methods-on-route branch September 18, 2024 06:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@std/http/route is doesn't automatically route HEAD requests
4 participants