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/01-fetch-basics/article.md
+94-93Lines changed: 94 additions & 93 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,36 +1,36 @@
1
1
2
-
# Fetch: Basics
2
+
# Fetch: Temel Bilgiler
3
3
4
-
Method `fetch()`is the modern way of sending requests over HTTP.
4
+
`fetch()`yöntemi, HTTP üzerinden istek göndermenin modern bir yoludur.
5
5
6
-
It evolved for several years and continues to improve, right now the support is pretty solid among browsers.
6
+
Birkaç yılda geliştirildi ve geliştirilmeye devam ediliyor, şu anda tarayıcılar arasında desteği oldukça sağlam.
7
7
8
-
The basic syntax is:
8
+
Temel sözdizimi şöyledir:
9
9
10
10
```js
11
11
let promise =fetch(url, [options])
12
12
```
13
13
14
-
-**`url`** -- the URL to access.
15
-
-**`options`** -- optional parameters: method, headers etc.
14
+
-**`url`** -- erişilecek URL.
15
+
-**`options`** -- isteğe bağlı parametreler: method, headers vb.
16
16
17
-
The browser starts the request right away and returns a `promise`.
17
+
Tarayıcı isteği başlatır ve bir `promise` döndürür.
18
18
19
-
Getting a response is usually a two-stage process.
19
+
Yanıt alma işlemi genellikle iki aşamalıdır.
20
20
21
-
**The `promise`resolves with an object of the built-in [Response](https://fetch.spec.whatwg.org/#response-class)class as soon as the server responds with headers.**
21
+
**Sunucu başlıklarını yanıtladığında, `promise`otomatik olarak oluşturulmuş [Response](https://fetch.spec.whatwg.org/#response-class)sınıfının bir nesnesiyle çözümlenir.**
22
22
23
+
Bu şekilde HTTP durumunu kontrol edebiliriz (status), başlıkları kontrol edebiliriz (head), ancak henüz gövdeyi (body) alamayız.
23
24
24
-
So we can check HTTP status, to see whether it is successful or not, check headers, but don't have the body yet.
25
+
`fetch`, HTTP isteği yapamadığında (örneğin, ağ sorunları varsa veya böyle bir site yoksa)
26
+
`promise `, reddeder. 404 veya 500 gibi HTTP hataları bile normal akış olarak kabul edilir.
25
27
26
-
The promise rejects if the `fetch` was unable to make HTTP-request, e.g. network problems, or there's no such site. HTTP-errors, even such as 404 or 500, are considered a normal flow.
28
+
Bunları response özelliklerinde görebiliriz:
27
29
28
-
We can see them in response properties:
30
+
-**`ok`** -- boolean, HTTP durum kodu 200-299 ise true döndürür.
31
+
-**`status`** -- HTTP durum kodu.
29
32
30
-
-**`ok`** -- boolean, `true` if the HTTP status code is 200-299.
31
-
-**`status`** -- HTTP status code.
32
-
33
-
For example:
33
+
Örneğin:
34
34
35
35
```js
36
36
let response =awaitfetch(url);
@@ -43,94 +43,95 @@ if (response.ok) { // if HTTP-status is 200-299
43
43
}
44
44
```
45
45
46
-
To get the response body, we need to use an additional method call.
46
+
Response gövdesini (body) almak için, ek bir yöntem çağrısı yapmamız gerekiyor.
47
+
48
+
`Response` gövdesine erişmek için birden fazla format ve özellik vardır:
47
49
48
-
`Response` provides multiple promise-based methods to access the body in various formats:
50
+
-**`response.json()`** -- yanıtı JSON nesnesi olarak ayrıştırır,
51
+
-**`response.text()`** -- yanıtı metin (text) olarak döndürür,
52
+
-**`response.formData()`** -- yanıtı FormData nesnesi olarak döndürür (form/çok parçalı kodlama),
53
+
-**`response.blob()`** -- yanıtı Blob türünde döndürür [Blob](info:blob) (binary data tipi (ikili)),
54
+
-**`response.arrayBuffer()`** -- yanıtı [ArrayBuffer](info:arraybuffer-binary-arrays) türünde döndürür (saf ikili veri),
55
+
- ek olarak, `response.body` bir, [ReadableStream](https://streams.spec.whatwg.org/#rs-class) nesnesidir, gövdeyi parça parça okumaya izin verir, daha sonra bir örnek göreceğiz.
49
56
50
-
-**`response.json()`** -- parse the response as JSON object,
51
-
-**`response.text()`** -- return the response as text,
52
-
-**`response.formData()`** -- return the response as FormData object (form/multipart encoding),
53
-
-**`response.blob()`** -- return the response as [Blob](info:blob) (binary data with type),
54
-
-**`response.arrayBuffer()`** -- return the response as [ArrayBuffer](info:arraybuffer-binary-arrays) (pure binary data),
55
-
- additionally, `response.body` is a [ReadableStream](https://streams.spec.whatwg.org/#rs-class) object, it allows to read the body chunk-by-chunk, we'll see an example later.
56
57
57
-
For instance, here we get a JSON-object with latest commits from GitHub:
58
+
Örneğin, burada GitHub'dan en son commitleri içeren bir JSON nesnesi alıyoruz:
58
59
59
60
```js run async
60
61
let response =awaitfetch('https://api.github.com/repos/javascript-tutorial/en.javascript.info/commits');
61
62
62
63
*!*
63
-
let commits =awaitresponse.json(); //read response body and parse as JSON
64
+
let commits =awaitresponse.json(); //yanıt gövdesini okuyun ve JSON olarak ayrıştırın
64
65
*/!*
65
66
66
67
alert(commits[0].author.login);
67
68
```
68
69
69
-
Or, the same using pure promises syntax:
70
+
Ya da promises sözdizimi kullanarak aynısını yapabilirsiniz:
To set a header, we can use the `headers`option, like this:
134
+
Bir başlık ayarlamak için aşağıdaki `headers`seçeneğini deneyebilirsiniz:
134
135
135
136
```js
136
137
let response =fetch(protectedUrl, {
@@ -139,8 +140,7 @@ let response = fetch(protectedUrl, {
139
140
}
140
141
});
141
142
```
142
-
143
-
...But there's a list of [forbidden HTTP headers](https://fetch.spec.whatwg.org/#forbidden-header-name) that we can't set:
143
+
...Ancak ayarlayamayacağımız yasaklı [HTTP başlıklarının](https://fetch.spec.whatwg.org/#forbidden-header-name) bir listesi var:
144
144
145
145
-`Accept-Charset`, `Accept-Encoding`
146
146
-`Access-Control-Request-Headers`
@@ -163,24 +163,24 @@ let response = fetch(protectedUrl, {
163
163
-`Proxy-*`
164
164
-`Sec-*`
165
165
166
-
These headers ensure proper and safe HTTP, so they are controlled exclusively by the browser.
166
+
Bu başlıklar düzgün ve güvenli HTTP isteği sağlar, bu nedenle yalnızca tarayıcı tarafından kontrol edilirler.
167
167
168
-
## POST requests
168
+
## POST istekleri
169
169
170
-
To make a `POST`request, or a request with another method, we need to use `fetch`options:
170
+
`POST`isteği veya başka bir yöntemle istek yapmak için `fetch`seçeneklerini kullanmamız gerekir:
171
171
172
-
-**`method`** -- HTTP-method, e.g. `POST`,
173
-
-**`body`** -- one of:
174
-
-a string (e.g. JSON),
175
-
-`FormData`object, to submit the data as`form/multipart`,
176
-
-`Blob`/`BufferSource`to send binary data,
177
-
-[URLSearchParams](info:url), to submit the data as `x-www-form-urlencoded`, rarely used.
172
+
-**`method`** -- HTTP-methodu, örn. `POST`,
173
+
-**`body`** -- örnekler:
174
+
- string değer (örn. JSON),
175
+
-`FormData`nesnesi olarak göndermek için`form/multipart`,
176
+
-`Blob`/`BufferSource`ikili (binary) veri göndermek için,
177
+
-[URLSearchParams](info:url), verileri `x-www-form-urlencoded`, göndermek için, nadiren kullanılır.
178
178
179
-
Let's see examples.
179
+
Hadi örneklere bakalım.
180
180
181
-
## Submit JSON
181
+
## Json Veri Göndermek
182
182
183
-
This code submits a `user`object as JSON:
183
+
Bu kod bir `user`objesini JSON olarak gönderir:
184
184
185
185
```js run async
186
186
let user = {
@@ -202,11 +202,11 @@ let result = await response.json();
202
202
alert(result.message);
203
203
```
204
204
205
-
Please note, if the body is a string, then `Content-Type`is set to `text/plain;charset=UTF-8`by default. So we use `headers`option to send `application/json`instead.
205
+
Kısa bir not, göndereceğim değer string ise, `Content-Type`değerini `text/plain;charset=UTF-8`olarak belirlememiz gerekiyor. Json veri göndereceğimiz için `headers`objesine `application/json`özelliğini ekliyoruz.
206
206
207
-
## Submit a form
207
+
## Form verisini göndermek
208
208
209
-
Let's do the same with an HTML `<form>`.
209
+
Aynı şeyi bir HTML `<form>`'u ile yapalım.
210
210
211
211
212
212
```html run
@@ -231,13 +231,15 @@ Let's do the same with an HTML `<form>`.
231
231
</script>
232
232
```
233
233
234
-
Here[FormData](https://xhr.spec.whatwg.org/#formdata)automatically encodes the form, `<input type="file">`fields are handled also, and sends it using `Content-Type: form/multipart`.
234
+
Burada[FormData](https://xhr.spec.whatwg.org/#formdata)formu otomatik olarak encode eder, `<input type="file">`alanları işlenir ve, `Content-Type: form/multipart` olarak gönderir.
235
235
236
-
## Submit an image
236
+
## Görselleri göndermek
237
237
238
-
We can also submit binary data directly using `Blob` or `BufferSource`.
238
+
Görsel verisini gönderirken ikili (binary) veri olarak göndermemiz gerekir.
239
239
240
-
For example, here's a `<canvas>` where we can draw by moving a mouse. A click on the "submit" button sends the image to server:
240
+
Direkt olarak `Blob` veya `BufferSource` kullanarak gönderebiliriz.
241
+
242
+
Örneğin, burada fareyi hareket ettirerek çizim yapabileceğimiz bir `<canvas>` var. "Gönder" butonuna tıklandığında görsel sunucuya gönderilir:
241
243
242
244
```html run autorun height="90"
243
245
<bodystyle="margin:0">
@@ -266,9 +268,9 @@ For example, here's a `<canvas>` where we can draw by moving a mouse. A click on
266
268
</body>
267
269
```
268
270
269
-
Here we also didn't need to set `Content-Type`manually, because a `Blob`object has a built-in type (here `image/png`, as generated by `toBlob`).
271
+
Burada ayrıca `Content-Type`manuel olarak ayarlamamız gerekmedi, çünkü `Blob`nesnesinin yerleşik bir türü vardır (burada `toBlob` tarafından oluşturulan `image/png`).
270
272
271
-
The`submit()`function can be rewritten without `async/await`like this:
273
+
Ayrıca`submit()`fonksiyonu `async/await`olmadan şu şekilde yazabiliriz:
272
274
273
275
```js
274
276
functionsubmit() {
@@ -283,11 +285,11 @@ function submit() {
283
285
}
284
286
```
285
287
286
-
## Custom FormData with image
288
+
## Görsel içeren Formdata'yı göndermek
287
289
288
-
In practice though, it's often more convenient to send an image as a part of the form, with additional fields, such as "name" and other metadata.
290
+
Pratikte bir görseli "name" ve diğer meta veriler gibi ek alanlarla birlikte formun bir parçası olarak göndermek genellikle daha uygundur.
289
291
290
-
Also, servers are usually more suited to accept multipart-encoded forms, rather than raw binary data.
292
+
Ayrıca, sunucular genellikle ham ikili veriler yerine çok parçalı kodlanmış formları(multipart-encoded forms) kabul etmeye daha uygundur.
291
293
292
294
```html run autorun height="90"
293
295
<bodystyle="margin:0">
@@ -323,39 +325,38 @@ Also, servers are usually more suited to accept multipart-encoded forms, rather
323
325
</body>
324
326
```
325
327
326
-
Now, from the server standpoint, the image is a "file" in the form.
328
+
Şimdi, sunucu açısından bakıldığında, görsel formdaki bir "dosya "dır.
327
329
328
-
## Summary
330
+
## Özet
329
331
330
-
A typical fetch request consists of two`awaits`:
332
+
Tipik bir fetch isteği iki bölümden oluşur `awaits`:
331
333
332
334
```js
333
-
let response =awaitfetch(url, options); // resolves with response headers
334
-
let result =awaitresponse.json(); // read body as json
335
-
```
335
+
let response =awaitfetch(url, options); // başlık kurallara göre okunur
336
+
let result =awaitresponse.json(); // gövdeyi json olarak geri döndürü
336
337
337
-
Or, promise-style:
338
+
Veya, promise stilinde:
338
339
```js
339
340
fetch(url, options)
340
341
.then(response => response.json())
341
342
.then(result => /* process result */)
342
343
```
343
344
344
-
Response properties:
345
-
-`response.status` -- HTTP code of the response,
346
-
-`response.ok` -- `true`is the status is 200-299.
347
-
-`response.headers` -- Map-like object with HTTP headers.
345
+
Yanıt(Response) Özellikleri
346
+
-`response.status`--HTTPdurum kodunu içerir,
347
+
-`response.ok`--`true`ise değer 200-299 arası olmalıdır
348
+
-`response.headers`--Başlıklarını içeren bir map benzeri nesne döndürür
348
349
349
-
Methods to get response body:
350
-
-**`response.json()`** -- parse the response as JSON object,
351
-
-**`response.text()`** -- return the response as text,
352
-
-**`response.formData()`** -- return the response as FormData object (form/multipart encoding),
353
-
-**`response.blob()`** -- return the response as [Blob](info:blob) (binary data with type),
354
-
-**`response.arrayBuffer()`** -- return the response as [ArrayBuffer](info:arraybuffer-binary-arrays) (pure binary data),
350
+
Yanıt Gövdesini (Response Body) alma yöntemleri:
351
+
-**`response.json()`**--yanıtı bir JSONobjesine çevirir,
352
+
-**`response.text()`**--yanıtı bir text olarak döndürür,
353
+
-**`response.formData()`**--yanıtı bir FormData objesi olarak döndürür (form/multipart encoding),
354
+
-**`response.blob()`**--yanıtı [Blob](info:blob) (binary data tipi) olarak döndürür,
355
+
-**`response.arrayBuffer()`**--yanıtı [ArrayBuffer](info:arraybuffer-binary-arrays) (saf ikili veri (binary)) olarak döndürür,
355
356
356
-
Fetch options so far:
357
-
-`method` -- HTTP-method,
358
-
-`headers` -- an object with request headers (not any header is allowed),
359
-
-`body` -- string/FormData/BufferSource/Blob/UrlSearchParams data to submit.
357
+
Şimdiye kadarki "Fetch" seçenekleri:
358
+
-`method`--HTTP methodları (POST,GET vs,),
359
+
-`headers`--istek başlıklarını içeren bir nesne (herhangi bir başlığa izin verilmez),
0 commit comments