You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 5-network/07-url/article.md
+37-37Lines changed: 37 additions & 37 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,28 +1,28 @@
1
1
2
2
# URL objects
3
3
4
-
The built-in [URL](https://url.spec.whatwg.org/#api)class provides a convenient interface for creating and parsing URLs.
4
+
La classe built-in [URL](https://url.spec.whatwg.org/#api)fornisce una comoda interfaccia per la creazione ed il parsing degli URL.
5
5
6
-
There are no networking methods that require exactly a`URL` object, strings are good enough. So technically we don't have to use `URL`. But sometimes it can be really helpful.
6
+
Non esistono metodi netowrking che richiedono esattamente un oggetto`URL` object, perché le stringhe sono già abbastanza adatte allo scopo. Quindi tecnicamente non dobbiamo usare `URL`. Talvolta però può essere davvero utile.
7
7
8
-
## Creating a URL
8
+
## Creare un URL
9
9
10
-
The syntax to create a new `URL` object:
10
+
La sintassi per creare un nuovo oggetto `URL`:
11
11
12
12
```js
13
13
newURL(url, [base])
14
14
```
15
15
16
-
-**`url`** -- the full URL or only path (if base is set, see below),
17
-
-**`base`** -- an optional base URL: if set and `url`argument has only path, then the URL is generated relative to`base`.
16
+
-**`url`** -- l'URL completo o solo il path (se base è stato impostato, gaurda sotto),
17
+
-**`base`** -- un base URL opzionale: se impostato ed l'argomento `url`contiene solo il path, URL viene generato relativamente a`base`.
18
18
19
-
For example:
19
+
Ad esempio:
20
20
21
21
```js
22
22
let url =newURL('https://javascript.info/profile/admin');
23
23
```
24
24
25
-
These two URLs are same:
25
+
Questi due URL sono identici:
26
26
27
27
```js run
28
28
let url1 =newURL('https://javascript.info/profile/admin');
The`URL`object immediately allows us to access its components, so it's a nice way to parse the url, e.g.:
44
+
L'oggetto`URL`ci permette immediatamente di accedere ai suoi componenti, in modo da avere un bel modo di effettuare il parse dell'url, come per esempio:
-`search` - una stringa contenente parametri, comincia con il punto interrogativo`?`
61
+
-`hash`cominca con il carattere cancelletto`#`
62
+
-possono essere presenti anche le proprietà `user`e`password`se è presente l'autenticazione HTTP: `http://login:password@site.com` (non illustrata sopra, perché usata raramente).
63
63
64
64
65
-
```smart header="We can pass `URL`objects to networking (and most other) methods instead of a string"
66
-
We can use a`URL`object in `fetch`or`XMLHttpRequest`, almost everywhere where a URL-string is expected.
65
+
```smart header="Possiamo passare gli oggetti `URL`ai metodi di networking (e molti altri) anziché una stringa"
66
+
Possiamo usare un oggetto`URL`dentro `fetch`o`XMLHttpRequest`, quasi ovunque ci si aspetti una stringa.
67
67
68
-
Generally, the`URL`object can be passed to any method instead of a string, as most methods will perform the string conversion, that turns a `URL`object into a string with full URL.
68
+
Generalmente, l'oggetto`URL`può essere passato a qualunque metodo al posto di una stringa, dal momento che la maggior parte dei metodi effettueranno una conversione in stringa, e trasformeneranno un oggetto `URL`in una stringa con l'URL completo.
69
69
```
70
70
71
71
## SearchParams "?..."
72
72
73
-
Let's say we want to create a url with given search params, for instance, `https://google.com/search?query=JavaScript`.
73
+
Mettiamo il caso che volessimo creare un url con dei parametri prestabiliti, ad esmepio, `https://google.com/search?query=JavaScript`.
74
74
75
-
We can provide them in the URL string:
75
+
Possiamo inserirli dentro la stringa URL:
76
76
77
77
```js
78
78
new URL('https://google.com/search?query=JavaScript')
79
79
```
80
80
81
-
...But parameters need to be encoded if they contain spaces, non-latin letters, etc (more about that below).
81
+
...Ma i parametri hanno bisogno di essere encodati se contengono spazi, lettere non latine, etc (più informazioni su questo in basso).
82
82
83
-
So there's a URL property for that: `url.searchParams`, an object of type[URLSearchParams](https://url.spec.whatwg.org/#urlsearchparams).
83
+
Abbiamo una proprietà URL appositamente per questo: `url.searchParams`, un oggetto di tipo[URLSearchParams](https://url.spec.whatwg.org/#urlsearchparams).
84
84
85
-
It provides convenient methods for search parameters:
85
+
Fornisce metodi comodi per i parametri di ricerca:
86
86
87
-
-**`append(name, value)`** -- add the parameter by`name`,
88
-
-**`delete(name)`** -- remove the parameter by`name`,
89
-
-**`get(name)`** -- get the parameter by`name`,
90
-
-**`getAll(name)`** -- get all parameters with the same `name` (that's possible, e.g. `?user=John&user=Pete`),
91
-
-**`has(name)`** -- check for the existence of the parameter by`name`,
92
-
-**`set(name, value)`** -- set/replace the parameter,
93
-
-**`sort()`** -- sort parameters by name, rarely needed,
94
-
- ...and it's also iterable, similar to`Map`.
87
+
-**`append(name, value)`** -- aggiunge il parametro per nome`name`,
88
+
-**`delete(name)`** -- rimuove il parametro partendo dal`name`,
89
+
-**`get(name)`** -- recupera il parametro dal nome`name`,
90
+
-**`getAll(name)`** -- recupera tutti i parametri con lo stesso `name` (un caso reale potrebbe essere ad esempio `?user=John&user=Pete`, nel caso di una select a scelta multipla),
91
+
-**`has(name)`** -- controlla l'esistenza del parametro a partire dal nome`name`,
92
+
-**`set(name, value)`** -- imposta/sostituisce il parametro,
93
+
-**`sort()`** -- ordina i parametri per nome, raramente necessario,
94
+
- ...ed è anche iterabile, similmente a`Map`.
95
95
96
-
An example with parameters that contain spaces and punctuation marks:
96
+
Ecco un esempio con parametri che contengono spazi e segni di punteggiatura:
97
97
98
98
```js run
99
99
let url =newURL('https://google.com/search');
100
100
101
-
url.searchParams.set('q', 'test me!'); //added parameter with a space and !
101
+
url.searchParams.set('q', 'test me!'); //aggiunto un parametro con spazio e !
0 commit comments