Okay. Let's add something new to our URLs called a
query parameter, also known as get parameters, and we'll talk
about this name shortly, when we start talking about HTTP.
Here is an example. We've got our normal URL or the
type of, the simple URL we just discussed, with a,
a simple path slash foo and we've added to the
end of this a question mark p equals one. And
this adds an actual, extra parameter whose name is P and
whose value is one. The format of a query parameter looks
like this. You've got name equals value, or in this case
P equals 1. And the value can be just about anything,
but it's good not to use question marks and other URL
characters, although you could if you really wanted. We can make
this a little bit more complicated by adding more query parameters.
Let's do that. We've added a second query parameter. The first
query parameter is separated from the UR, URL using a, question
mark. All of the following parameters are separated from each other
using ampersands. First one gets a question mark. The next one
gets an ampersand. In this case, the new parameter is Q,
and it equals the string neat. So, we have these query
parameters. What are they for? They're for basically, when you, when
you make a request for this path, this is extra information
the server gets, and there's all sorts of things you can
do with this. If this is a, a web application doing fancy
things these parameters might mean something. It can affect the
caching because technically it changes the entire URL. So there
are all sorts of handy uses that we'll discuss later
in the class for what these query parameters can do. But
they are separate from the path. But they are included
in part of the whole URL that the server sees
when you make a request. In the following URL, what
is the value of the Z parameter? Here is your URL.
Ok, ahora agreguemos algo nuevo a nuestra URL llamado
parámetro de búsqueda, también conocidos como parámetros "get", y hablaremos
sobre este nombre dentro de poco, cuando empecemos a hablar sobre HTTP.
Aquí tenemos un ejemplo. Tenemos nuestra URL normal,
la simple URL que hemos discutido,
con una simple ruta slash foo y lo agregamos
al final del signo de interrogación p igual a uno.
La cual agrega un parámetro extra cuyo nombre es P y
cuyo valor es uno. El formato de un parámetro de búsqueda luce así:
Tenemos el nombre igual al valor, o en este caso
P igual 1. Y el valor puede ser cualquier cosa,
pero es buena práctica no usar signos de interrogación y otros caracteres URL,
sin embargo podrías hacerlo si en realidad lo deseas. Podríamos hacer
esto un poco más complicado agregando más parámetros de búsqueda.
Hagámoslo. Hemos agregado un segundo parámetro de búsqueda. El primer
parámetro de búsqueda es separado de la URL usando un signo de interrogación.
Los siguientes parámetros de búsqueda son separados usando amperands.
El primero utiliza un signo de interrogación. El siguiente
utiliza un ampersand. En este caso, el nuevo parámetro es Q,
y es igual a la cadena "neat". Así, tenemos estos parámetros de búsqueda.
¿Para qué se utilizan? Básicamente,
cuando hagas una petición a esta ruta, ellos son información extra
que el servidor recibe, y hay un montón de cosas que
podrás hacer con ellos. Si esto fuese una aplicación Web haciendo una búsqueda,
éstos parámetros podrían significar algo. Podría afectar el
almacenamiento en caché porque técnicamente cambia toda la URL.
Hay todo tipo de usos que discutiremos luego en esta clase
sobre lo que los parámetros de búsqueda pueden hacer. Pero
ellos van separados de la ruta. Pero van incluídos
en parte en toda la URL que el server ve
cuando haces una petición. En la siguiente URL,
¿Cuál es el valor del parámetro Z? Aquí está la URL.
URLに新しい要素を加えたいと思います
クエリパラメータまたはGETパラメータといいます
これらは後でHTTPの説明の際にも登場します
例を紹介します この部分は普通のURLです
先ほど紹介したとおりの形状です
/fooというシンプルなパスがついています
ですが末尾に?p=1という記号がついています
これはpという名で値が1であるパラメータが
追加されたことを表しています
クエリパラメータはこのように
パラメータ名=値の形式で記述します
値は数字以外でも構いませんが
URLで使用している文字列は避けた方が無難です
絶対にダメというわけではありません
さらにクエリパラメータを加えて
複雑にすることもできます
2つ目のクエリパラメータを付けてみましょう
1つ目のクエリパラメータは?で区切りますが
2つ目以降のクエリパラメータを区切るには&を使います
1つ目は?で2つ目以降は&です
この場合2つ目のパラメータ名はqで
値は文字列neatとなります
ではクエリパラメータの役割は何かというと
このパスにリクエストを送信する際に
サーバが受け取る付加情報です
これを使うと様々なことができます
Webアプリケーションを付けたり
キャッシュを変えることもできます
クエリパラメータはURL全体に変化を与えます
クエリパラメータの便利な利用法は
今後のレッスンでたくさんご紹介します
クエリパラメータはパスから独立していますが
リクエスト送信時には
サーバはURLの一部として認識します
それでは下のURLでパラメータzの値は何でしょう?