Skip to content

Commit dd843fa

Browse files
authored
Merge pull request #345 from dilarauluturhan/master
fetch api
2 parents 7490fe6 + 866c198 commit dd843fa

File tree

1 file changed

+74
-75
lines changed

1 file changed

+74
-75
lines changed

5-network/05-fetch-api/article.md

Lines changed: 74 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,97 @@
11

22
# Fetch API
33

4-
So far, we know quite a bit about fetch.
4+
Şimdiye kadar fetch hakkında biraz bilgi edindik.
55

6-
Now let's see the rest of API, to cover all its abilities.
6+
Şimdi tamamını kapsayacak şekilde API’nin tüm yeteneklerini görelim.
77

8-
Here's the full list of all possible fetch options with their default values (alternatives in comments):
8+
Varsayılan değerleriyle olası tüm fetch işlemlerinin tam listesi işte burada (diğer alternatifler yorumlarda)
99

1010
```js
1111
let promise = fetch(url, {
12-
method: "GET", // POST, PUT, DELETE, etc.
12+
method: "GET", // POST, PUT, DELETE vb.
1313
headers: {
1414
"Content-Type": "text/plain;charset=UTF-8" // for a string body, depends on body
1515
},
16-
body: undefined // string, FormData, Blob, BufferSource, or URLSearchParams
17-
referrer: "about:client", // "" for no-referrer, or an url from the current origin
16+
body: undefined // string, FormData, Blob, BufferSource ya da URLSearchParams
17+
referrer: "about:client", // no-referrer için "" ya da mevcut başlangıç noktasından bir URL
1818
referrerPolicy: "no-referrer-when-downgrade", // no-referrer, origin, same-origin...
1919
mode: "cors", // same-origin, no-cors
2020
credentials: "same-origin", // omit, include
21-
cache: "default", // no-store, reload, no-cache, force-cache, or only-if-cached
21+
cache: "default", // no-store, reload, no-cache, force-cache ya da only-if-cached
2222
redirect: "follow", // manual, error
23-
integrity: "", // a hash, like "sha256-abcdef1234567890"
23+
integrity: "", // bir hash, "sha256-abcdef1234567890" gibi
2424
keepalive: false, // true
25-
signal: undefined, // AbortController to abort request
25+
signal: undefined, // İsteği iptal etmek için AbortController
2626
window: window // null
2727
});
2828
```
2929

30-
An impressive list, right?
30+
Etkileyici bir liste, değil mi?
3131

32-
We fully covered `method`, `headers` and `body` in the chapter <info:fetch-basics>.
32+
<info:fetch-basics> bölümünde `method`, `headers` ve `body` tamamıyla ele alındı .
3333

34-
The `signal` option is covered in <info:fetch-abort>.
34+
`signal` ise <info:fetch-abort> bölümünde ele alındı.
3535

36-
Now let's explore the rest of options.
36+
Şimdi diğer özelliklerini inceleyelim.
3737

3838
## referrer, referrerPolicy
3939

40-
These options govern how `fetch` sets HTTP `Referer` header.
40+
Bu özellikler `fetch` işleminin HTTP `Referer` bilgisini nasıl ayarladığını düzenler.
4141

42-
That header contains the url of the page that made the request. In most scenarios, it plays a very minor informational role, but sometimes, for security purposes, it makes sense to remove or modify it.
43-
.
42+
Bu başlık, istek yapan sayfanın URL’sini içerir. Çoğu durumda çok küçük bir bilgilendirme rolü oynar ama bazen güvenlik amacıyla kaldırmak veya değiştirmek daha mantıklıdır.
4443

45-
**The `referrer` option allows to set any `Referer` within the current origin) or disable it.**
44+
**`referrer` özelliği başlangıçtaki mevcut herhangi bir `Referer`'ın ayarlanmasına veya devre dışı bırakılmasına izin verir.**
4645

47-
To send no referer, set an empty string:
46+
Referer göndermemek için boş bir string yazın:
4847
```js
4948
fetch('/page', {
5049
*!*
51-
referrer: "" // no Referer header
50+
referrer: "" // Referer içeriği boş
5251
*/!*
5352
});
5453
```
5554

56-
To set another url within the current origin:
55+
Mevcut başlangıç noktasında başka bir URL ayarlamak için:
5756

5857
```js
5958
fetch('/page', {
60-
// assuming we're on https://javascript.info
61-
// we can set any Referer header, but only within the current origin
59+
// https://javascript.info’da olduğumuzu varsayarsak
60+
// herhangi bir Referer bilgisini ayarlayabiliriz ancak sadece mevcut başlangıç noktası dahilinde
6261
*!*
6362
referrer: "https://javascript.info/anotherpage"
6463
*/!*
6564
});
6665
```
6766

68-
**The `referrerPolicy` option sets general rules for `Referer`.**
67+
**`referrerPolicy`, `Referer` için genel kurallar belirler.**
6968

70-
Possible values are described in the [Referrer Policy specification](https://w3c.github.io/webappsec-referrer-policy/):
69+
Olası değerler [Referrer Policy](https://w3c.github.io/webappsec-referrer-policy/) spesifikasyonunda açıklanmıştır:
7170

72-
- **`"no-referrer-when-downgrade"`** -- default value: `Referer` is sent always, unless we send a request from HTTPS to HTTP (to less secure protocol).
73-
- **`"no-referrer"`** -- never send `Referer`.
74-
- **`"origin"`** -- only send the origin in `Referer`, not the full page URL, e.g. `http://site.com` instead of `http://site.com/path`.
75-
- **`"origin-when-cross-origin"`** -- send full referrer to the same origin, but only the origin part for cross-origin requests.
76-
- **`"same-origin"`** -- send full referrer to the same origin, but no referer for for cross-origin requests.
77-
- **`"strict-origin"`** -- send only origin, don't send referrer for HTTPS→HTTP requests.
78-
- **`"strict-origin-when-cross-origin"`** -- for same-origin send full referrer, for cross-origin send only origin, unless it's HTTPS→HTTP request, then send nothing.
79-
- **`"unsafe-url"`** -- always send full url in `Referer`.
71+
- **`"no-referrer-when-downgrade"`** -- Varsayılan değer: HTTPS'ten HTTP'ye bir istek göndermediğimiz sürece `Referer` her zaman gönderilir (güvenlik protokolü daha az).
72+
- **`"no-referrer"`** -- Hiçbir zaman `Referer` göndermez.
73+
- **`"origin"`** -- Belli bir URL'yi değil, sadece `Referer` kaynağını gönderir. Örneğin `http://site.com/path` yerine `http://site.com` gibi.
74+
- **`"origin-when-cross-origin"`** -- Referer'ın tamamını aynı kaynağa gönderir ancak kaynaklar arasındaki istekler için yalnızca kaynak kısmını gönderir.
75+
- **`"same-origin"`** -- Aynı kök URL'ye tam Referer gönderir, ancak farklı kök URL'ler arasındaki istekler için Referer göndermez.
76+
- **`"strict-origin"`** -- Sadece kök URL'yi gönderir, HTTPS→HTTP istekleri için Referer göndermez.
77+
- **`"strict-origin-when-cross-origin"`** -- Aynı kök URL'ye tam Referer gönderir, farklı kök URL'ler arasındaki istekler için sadece kök URL gönderir ancak HTTPS→HTTP isteği durumunda hiçbir şey göndermez.
78+
- **`"unsafe-url"`** -- Her zaman `Referer`'da tam URL'yi gönderir.
8079

81-
Let's say we have an admin zone with URL structure that shouldn't be visible from outside.
80+
Diyelim ki dışarıdan görünmemesi gereken URL yapılarına sahip bir yönetici bölgesi (admin zone) var.
8281

83-
If we send a cross-origin `fetch`, then by default it sends the `Referer` header with the full url of our page (except when we request from HTTPS to HTTP, then no `Referer`).
82+
Eğer farklı bir kaynaktan (cross-origin) bir istek gönderirsek varsayılan olarak isteğimiz `Referer` başlığını sayfanın tam URL'siyle birlikte gönderir (ancak HTTPS'ten HTTP'ye istek gönderdiğimizde `Referer` gönderilmez).
8483

85-
E.g. `Referer: https://javascript.info/admin/secret/paths`.
84+
Örneğin `Referer: https://javascript.info/admin/secret/paths`.
8685

87-
If we'd like to totally hide the referrer:
86+
Referrer'ı tamamen gizleme istiyorsak:
8887

8988
```js
9089
fetch('https://another.com/page', {
91-
referrerPolicy: "no-referrer" // no Referer, same effect as referrer: ""
90+
referrerPolicy: "no-referrer" // no Referer, referrer: ""'la aynı işlevi görür
9291
});
9392
```
9493

95-
Otherwise, if we'd like the remote side to see where the request comes from, we can send only the "origin" part of the url:
94+
Aksi takdirde, uzak tarafın isteğin nereden geldiğini görmesini istiyorsak, sadece URL'nin "origin" (kök) kısmını gönderebiliriz:
9695

9796
```js
9897
fetch('https://another.com/page', {
@@ -102,72 +101,72 @@ fetch('https://another.com/page', {
102101

103102
## mode
104103

105-
The `mode` option serves as a safe-guard that prevents cross-origin requests:
104+
`mode` seçeneği, kaynaklararası istekleri önlemek için bir güvenlik önlemi olarak hizmet eder.
106105

107-
- **`"cors"`** -- the default, cross-origin requests are allowed, as described in <info:fetch-crossorigin>,
108-
- **`"same-origin"`** -- cross-origin requests are forbidden,
109-
- **`"no-cors"`** -- only simple cross-origin requests are allowed.
106+
- **`"cors"`** -- Varsayılan olarak <info:fetch-crossorigin>'de açıklandığı gibi kaynaklararası isteklere izin verilir,
107+
- **`"same-origin"`** -- Kaynaklararası isteklere izin verilmez,
108+
- **`"no-cors"`** -- Sadece basit olan kaynaklararası isteklere izin verilir.
110109

111-
That may be useful in contexts when the fetch url comes from 3rd-party, and we want a "power off switch" to limit cross-origin capabilities.
110+
Bu, fetch işleminin URL'sinin üçüncü taraf bir kaynaktan geldiği durumlarda ve kaynaklararası yeteneklerini sınırlamak için bir "güç kapama anahtarı" istediğimiz durumlarda faydalı olabilir.
112111

113112
## credentials
114113

115-
The `credentials` option specifies whether `fetch` should send cookies and HTTP-Authorization headers with the request.
114+
`credentials`, `fetch` işleminin isteğiyle birlikte çerezleri ve HTTP-Authorization başlıklarını gönderip göndermeyeceğini belirtir.
116115

117-
- **`"same-origin"`** -- the default, don't send for cross-origin requests,
118-
- **`"include"`** -- always send, requires `Accept-Control-Allow-Credentials` from cross-origin server,
119-
- **`"omit"`** -- never send, even for same-origin requests.
116+
- **`"same-origin"`** -- Varsayılan değerdir, kaynaklararası istekler için göndermez,
117+
- **`"include"`** -- Her zaman gönderir ancak kaynaklararası sunucudan `Accept-Control-Allow-Credentials` gerektirir,
118+
- **`"omit"`** -- Hiçbir zaman göndermez hatta aynı kök URL'ye sahip istekler için bile göndermez.
120119

121120
## cache
122121

123-
By default, `fetch` requests make use of standard HTTP-caching. That is, it honors `Expires`, `Cache-Control` headers, sends `If-Modified-Since`, and so on. Just like regular HTTP-requests do.
122+
Varsayılan olarak `fetch` istekleri standart HTTP önbellekleme kurallarını kullanır. Yani `Expires`, `Cache-Control` başlıklarını dikkate alıp `If-Modified-Since` gibi başlıklar gönderir. Adeta normal HTTP istekleri gibi davranır.
124123

125-
The `cache` options allows to ignore HTTP-cache or fine-tune its usage:
124+
`cache`, HTTP önbelleğini yok saymak veya kullanımını ayarlamak için kullanılır:
126125

127-
- **`"default"`** -- `fetch` uses standard HTTP-cache rules and headers;
128-
- **`"no-store"`** -- totally ignore HTTP-cache, this mode becomes the default if we set a header `If-Modified-Since`, `If-None-Match`, `If-Unmodified-Since`, `If-Match`, or `If-Range`;
129-
- **`"reload"`** -- don't take the result from HTTP-cache (if any), but populate cache with the response (if response headers allow);
130-
- **`"no-cache"`** -- create a conditional request if there is a cached response, and a normal request otherwise. Populate HTTP-cache with the response;
131-
- **`"force-cache"`** -- use a response from HTTP-cache, even if it's stale. If there's no response in HTTP-cache, make a regular HTTP-request, behave normally;
132-
- **`"only-if-cached"`** -- use a response from HTTP-cache, even if it's stale. If there's no response in HTTP-cache, then error. Only works when `mode` is `"same-origin"`.
126+
- **`"default"`** -- `fetch`, standart HTTP önbellekleme kurallarını ve başlıklarını kullanır;
127+
- **`"no-store"`** -- HTTP önbelleğini tamamen yok sayar. Eğer `If-Modified-Since`, `If-None-Match`, `If-Unmodified-Since`, `If-Match` veya `If-Range` başlıklarından herhangi birini set edersek bu mod varsayılan olur;
128+
- **`"reload"`** -- Sonucu HTTP önbellekten almadan (eğer varsa) cevap ile önbelleği doldurur (eğer cevap başlıkları buna izin veriyorsa);
129+
- **`"no-cache"`** -- Önbellekte bir yanıt varsa koşullu bir istek oluşturur aksi takdirde normal bir istek yapar. HTTP önbelleği ile cevabı doldurur;
130+
- **`"force-cache"`** -- Yanıtı HTTP önbelleğinden alır hatta eskimiş olsa bile. Eğer HTTP önbelleğinde yanıt yoksa normal bir HTTP isteği yapar ve normal davranır;
131+
- **`"only-if-cached"`** -- Yanıtı HTTP önbelleğinden alır hatta eskimiş olsa bile. Eğer HTTP önbelleğinde yanıt yoksa hata döner. Sadece `mode` değeri `"same-origin"` olduğunda çalışır.
133132

134133
## redirect
135134

136-
Normally, `fetch` transparently follows HTTP-redirects, like 301, 302 etc.
135+
Normalde `fetch` işlemi 301, 302 gibi HTTP yönlendirmelerini şeffaf bir şekilde takip eder.
137136

138-
The `redirect` option allows to change that:
137+
`redirect` seçeneği bu davranışı değiştirmemizi sağlar:
139138

140-
- **`"follow"`** -- the default, follow HTTP-redirects,
141-
- **`"error"`** -- error in case of HTTP-redirect,
142-
- **`"manual"`** -- don't follow HTTP-redirect, but `response.url` will be the new URL, and `response.redirected` will be `true`, so that we can perform the redirect manually to the new URL (if needed).
139+
- **`"follow"`** -- Varsayılan değerdir, HTTP yönlendirmelerini takip eder,
140+
- **`"error"`** -- HTTP yönlendirmesi durumunda hata verir,
141+
- **`"manual"`** -- HTTP yönlendirmelerini takip etmez ancak `response.url` yeni URL olacak ve `response.redirected` değeri `true` olacak böylece ihtiyaç halinde yönlendirmeyi manuel olarak yeni URL'ye gerçekleştirebiliriz.
143142

144143
## integrity
145144

146-
The `integrity` option allows to check if the response matches the known-ahead checksum.
145+
`integrity`, yanıtın önceden bilinen bir karma (checksum) ile eşleşip eşleşmediğini kontrol etmemize olanak sağlar.
147146

148-
As described in the [specification](https://w3c.github.io/webappsec-subresource-integrity/), supported hash-functions are SHA-256, SHA-384, and SHA-512, there might be others depending on a browser.
147+
[specification](https://w3c.github.io/webappsec-subresource-integrity/)'da açıklandığı gibi, desteklenen fonksiyonlar SHA-256, SHA-384 ve SHA-512'dir ve tarayıcıya göre başka fonksiyonları da olabilir.
149148

150-
For example, we're downloading a file, and we know that it's SHA-256 checksum is "abc" (a real checksum is longer, of course).
149+
Örneğin bir dosyayı indiriyoruz ve dosyanın SHA-256 karma değerinin "abc" olduğunu biliyoruz (gerçek bir karma değeri tabii ki daha uzundur).
151150

152-
We can put it in the `integrity` option, like this:
151+
Bunu aşağıdaki gibi `integrity` seçeneğine ekleyebiliriz:
153152

154153
```js
155154
fetch('http://site.com/file', {
156155
integrity: 'sha256-abd'
157156
});
158157
```
159158

160-
Then `fetch` will calculate SHA-256 on its own and compare it with our string. In case of a mismatch, an error is triggered.
159+
Daha sonra `fetch` işlemi kendi başına SHA-256 hesaplar ve hesapladığı değeri bizim verdiğimiz değerle karşılaştırır. Eşleşme olmaması durumunda bir hata tetiklenir.
161160

162161
## keepalive
163162

164-
The `keepalive` option indicates that the request may outlive the page.
163+
`keepalive`, isteğin sayfadan ayrıldıktan sonra dahi gerçekleştirilebileceğini belirtir.
165164

166-
For example, we gather statistics about how the current visitor uses our page (mouse clicks, page fragments he views), to improve user experience.
165+
Örneğin mevcut ziyaretçinin sayfamızı nasıl kullandığıyla ilgili istatistikleri topluyoruz (fare tıklamaları, görüntülediği sayfa parçaları) ve kullanıcı deneyimini iyileştirmek amacıyla bunları sunucumuza kaydetmek istiyoruz.
167166

168-
When the visitor leaves our page -- we'd like to save it on our server.
167+
Ziyaretçi sayfadan ayrıldığında bu bilgileri sunucumuza kaydetmek istiyoruz.
169168

170-
We can use `window.onunload` for that:
169+
Bunu yapmak için `window.onunload` özelliğini kullanabiliriz:
171170

172171
```js run
173172
window.onunload = function() {
@@ -181,10 +180,10 @@ window.onunload = function() {
181180
};
182181
```
183182

184-
Normally, when a document is unloaded, all associated network requests are aborted. But `keepalive` option tells the browser to perform the request in background, even after it leaves the page. So it's essential for our request to succeed.
183+
Normalde bir belge yüklenirken ilişkili tüm ağ istekleri iptal edilir ancak `keepalive` tarayıcının isteği arka planda yapmasını ve sayfadan ayrıldıktan sonra bile gerçekleştirmesini sağlar. Bu nedenle isteğin başarıyla gerçekleşmesi için bu seçeneğin kullanılması önemlidir.
185184

186-
- We can't send megabytes: the body limit for keepalive requests is 64kb.
187-
- If we gather more data, we can send it out regularly, then there won't be a lot for the "onunload" request.
188-
- The limit is for all currently ongoing requests. So we cheat it by creating 100 requests, each 64kb.
189-
- We don't get the server response if the request is made `onunload`, because the document is already unloaded at that time.
190-
- Usually, the server sends empty response to such requests, so it's not a problem.
185+
- Megabaytlarca veri gönderemeyiz: `keepalive` istekleri için sınır 64 KB'dır
186+
- Daha fazla veri toplarsak düzenli olarak göndermemiz gerekir böylece "onunload" isteği için çok fazla veri olmaz.
187+
- Limit tüm devam eden istekler için geçerlidir. Bu nedenle 64 KB boyutunda 100 istek oluşturarak bu sınırı aşabiliriz.
188+
- `onunload` durumunda sunucu cevabını alamayız çünkü belge o zaman zaten yüklenmemiştir.
189+
- Genellikle sunucu böyle isteklere boş bir cevap gönderir bu nedenle bu durumda bir sorun olmaz.

0 commit comments

Comments
 (0)