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: Add new shortcuts for request/response #62

Merged
merged 4 commits into from
Jan 26, 2022
Merged

Conversation

yusukebe
Copy link
Member

@yusukebe yusukebe commented Jan 24, 2022

Add new shortcuts for Requests:

c.req.header('Header-Name')
c.req.param('q') // instead of c.req.params

Add new shortcuts for Response:

c.header('Header-Name', 'Header-Value')
c.status(201)
c.statusText('This status text')
return c.text('This is Body text')
/*
new Response('This is Body text', {
  status: 201,
  statusText: 'This status text',
  headers: { 'Header-Name': 'Header-Value', 'Content-Type': 'plain/text' },
})
*/

@yusukebe yusukebe mentioned this pull request Jan 24, 2022
Closed
60 tasks
@@ -6,6 +6,10 @@ export const defaultMiddleware = async (c: Context, next: Function) => {
const url = new URL(c.req.url)
return url.searchParams.get(key)
}
c.req.params = c.req.param // alias
Copy link
Contributor

@metrue metrue Jan 25, 2022

Choose a reason for hiding this comment

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

Why we just make ctx.req.params at the first place to avoid this alias?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Why we have both params and param in a Request, is possible to make it only params or param?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, we make it param only because params is just for backward compatibility and that we have both may cause confusion.

@yusukebe yusukebe changed the title [WIP] feat: Add new shortcuts for request/response feat: Add new shortcuts for request/response Jan 26, 2022
@yusukebe yusukebe merged commit 6123fdc into master Jan 26, 2022
yusukebe added a commit that referenced this pull request Jan 26, 2022
* Add new shortcuts for request/response

* We have only `param`, we can not use `params`

* Update readme

* tweak
@yusukebe yusukebe deleted the feat/new-shortcuts branch January 26, 2022 04:31
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.

None yet

2 participants