22 Mart 2021 Pazartesi

HTTP Durum Kodları - 2XX SUCCESS Kodları

Giriş
Açıklaması şöyle.
The 2xx (Successful) class of status code indicates that the client's request was successfully received, understood, and accepted.
200 - OK
Açıklaması şöyle.
200 means the server experienced no problems and has a representation of the results for the client to consume.
Sunucudaki bir dosyaya GET isteği gönderdiğimizi varsayalım. Cevap olarak 200 ile başlayan bir satır almamız tüm dosyayı indirdiğimiz anlamına gelmez. Http isteği bir bütün olarak düşünülmeli. Açıklaması şöyle.
HTTP 200 is generated by the server, and only means that it understood the request and thinks it is able to fulfill it (e.g. the file is actually there). All sorts of errors may occur during the transmission of the full response document (network connection breaking, packet loss, etc) which will not show up in the HTTP response, but need to be detected separately.
201 Created
Açıklaması şöyle. PUT isteği ile bir resource ilk defa yaratılırsa bu cevap döner.
If the target resource does not have a current representation and the PUT successfully creates one, then the origin server MUST inform the user agent by sending a 201 (Created) response. If the target resource does have a current representation and that representation is successfully modified in accordance with the state of the enclosed representation, then the origin server MUST send either a 200 (OK) or a 204 (No Content) response to indicate successful completion of the request.
202 Accepted - Async taskİsteğin alındığını belirtir. 200'den farkı gönderilen isteğin daha sonra asenkron olarak işleneceğini ifade etmesidir.

Örnek
Açıklaması şöyle
Assume that your web/mobile application UI accepts a task request from a user, such as uploading an image or creating a profile. The backend will take considerable time to process the task, which can’t be completed within the scope of an HTTP request.

The typical pattern is that the backend accepts the request, validates it, and returns HTTP 202 status to the UI, denoting that the task has been accepted for processing. 

203 - Non-Authoritative Information (since HTTP/1.1)
Açıklaması şöyle.
203 means that the response was modified between the authoritative server and the client. 
204 - No Content
Client tarafından gönderilen isteğe "No Result" gibi bir cevap vermek istersek kullanılabilir. Rest servisini normalde vereceği cevap şöyle olsun.
{
  "results": [
    {
      "name": "Pancakes",
      ....
    },
    {
      "name": "French Fries",
      ....
    }
  ]
}
Ancak dönülen cevap boş ise 204 ve şöyle bir cevap gönderilebilir.
{
  "results": []
}
205 - Reset Content
Örnek ver

206 - Partial Content
Açıklaması şöyle.
206 appears to be designed for returning a large resource over multiple responses. It also requires that the client ask for a part of the content in the headers (so pagination via query strings does not qualify).
207 Multi-Status
Açıklaması şöyle. Birden fazla işin sonucu dönüleceği zaman kullanılabilir.
A Multi-Status response conveys information about multiple resources in situations where multiple status codes might be appropriate. The default Multi-Status response body is a text/xml or application/xml HTTP entity with a 'multistatus' root element. Further elements contain 200, 300, 400, and 500 series status codes generated during the method invocation. 100 series status codes SHOULD NOT be recorded in a 'response' XML element.
Although '207' is used as the overall response status code, the recipient needs to consult the contents of the multistatus response body for further information about the success or failure of the method execution. The response MAY be used in success, partial success and also in failure situations.

Hiç yorum yok:

Yorum Gönder