@@ -1973,54 +1973,31 @@ Accept: text/plain\r\n
1973
1973
\r\n
1974
1974
```
1975
1975
1976
- Then ` request. url` will be :
1976
+ To parse the url into its parts The WHATWG URL API can be used :
1977
1977
1978
- <!-- eslint-disable semi -->
1979
1978
``` js
1980
- ' /status?name=ryan '
1979
+ new URL ( request . url , ` http:// ${ request . headers . host } ` );
1981
1980
```
1982
1981
1983
- To parse the url into its parts ` require('url').parse(request.url) `
1984
- can be used:
1982
+ When ` request.url ` is ` '/status?name=ryan' ` and ` request.headers.host ` is ` 'localhost:3000' ` :
1985
1983
1986
1984
``` console
1987
1985
$ node
1988
- > require(' url' ).parse(' /status?name=ryan' )
1989
- Url {
1990
- protocol: null,
1991
- slashes: null,
1992
- auth: null,
1993
- host: null,
1994
- port: null,
1995
- hostname: null,
1996
- hash: null,
1997
- search: '?name=ryan',
1998
- query: 'name=ryan',
1986
+ > new URL(' /status?name=ryan' , ' localhost:3000' )
1987
+ URL {
1988
+ href: 'http://localhost:3000/status?name=ryan',
1989
+ origin: 'http://localhost:3000',
1990
+ protocol: 'http:',
1991
+ username: '',
1992
+ password: '',
1993
+ host: 'localhost:3000',
1994
+ hostname: 'localhost',
1995
+ port: '3000',
1999
1996
pathname: '/status',
2000
- path: '/status?name=ryan',
2001
- href: '/status?name=ryan' }
2002
- ```
2003
-
2004
- To extract the parameters from the query string, the
2005
- ` require('querystring').parse ` function can be used, or
2006
- ` true ` can be passed as the second argument to ` require('url').parse ` :
2007
-
2008
- ``` console
2009
- $ node
2010
- > require(' url' ).parse(' /status?name=ryan' , true)
2011
- Url {
2012
- protocol: null,
2013
- slashes: null,
2014
- auth: null,
2015
- host: null,
2016
- port: null,
2017
- hostname: null,
2018
- hash: null,
2019
1997
search: '?name=ryan',
2020
- query: { name: 'ryan' },
2021
- pathname: '/status',
2022
- path: '/status?name=ryan',
2023
- href: '/status?name=ryan' }
1998
+ searchParams: URLSearchParams { 'name' => 'ryan' },
1999
+ hash: ''
2000
+ }
2024
2001
```
2025
2002
2026
2003
## http.METHODS
0 commit comments