SDAPI HTTP methods 2.0

A key characteristic of a RESTful Web API is the explicit use of HTTP methods, as defined by RFC 2616. The Script Debugger API supports these methods, as described in the following sections.

GET

The GET method retrieves resources on the server. The GET method is a safe method, which means that it should never change the state of the server or have side effects. Consequently, a GET request never initiates transactions on the server.

A typical GET request and its response look like this:

REQUEST:
GET /s/-/dw/debugger/v1_0/breakpoints/40 HTTP/1.1
Authorization: Basic YWRtaW46RGVtYW5kd2FyZTEh
x-dw-client-id: DebuggerTest
Content-Type: application/json
Content-Length: 0

RESPONSE:
HTTP/1.1 200 OK
{
  "_v":"2.0",
  "id":40,
  "line_number":20,
  "script_path":"/app_storefront_controllers/cartridge/controllers/Cart.js"
}

This sample shows a typical GET request retrieving a list of Breakpoint resources. The response has HTTP status code 200, which indicates resources were found and are contained in response body. The response contains the "Content-Type" header, which is set to "application/json" plus the charset definition ("UTF-8").

DELETE

The DELETE method removes one or more resources on the server. DELETE is an idempotent method, which means repeating a request should have the same effect as making the request just once. This implies that the server returns HTTP status code 204 (NO CONTENT) even if the server removed the resource previously.

The following example shows how to remove a resource that is addressed by an Identifier in the URL:

REQUEST:
DELETE /s/-/dw/debugger/v1_0/breakpoints/40 HTTP/1.1
Authorization: Basic YWRtaW46RGVtYW5kd2FyZTEh
x-dw-client-id: DebuggerTest
Content-Type: application/json
Content-Length: 0

RESPONSE:
HTTP/1.1 204 No Content
Content-Length: 0

The request is similar to the previous GET request, except the HTTP method changed. The response status code is 204, which means the server successfully fulfilled the request but returned no content.

POST

The POST method is neither safe (because requests can affect the server state) nor idempotent (because multiple requests potentially return different results).

The Script Debugger API uses POST only for two purposes:

REQUEST:
POST /s/-/dw/debugger/v1_0/breakpoints HTTP/1.1
Authorization: Basic YWRtaW46RGVtYW5kd2FyZTEh
x-dw-client-id: DebuggerTest
Content-Type: application/json
{
  "_v":"2.0",
  "breakpoints":
    [
      {"line_number":20,"script_path":"/app_storefront_controllers/cartridge/controllers/Cart.js"},
      {"line_number":25,"script_path":"/app_storefront_controllers/cartridge/scripts/models/CartModel.js"}
    ]
} 

RESPONSE:
HTTP/1.1 200 OK
Content-Type: application/json;charset=UTF-8
{
  "_v":"2.0",
  "breakpoints":
    [
      {"id":1, "line_number":20,"script_path":"/app_storefront_controllers/cartridge/controllers/Cart.js"},
      {"id":2, "line_number":25,"script_path":"/app_storefront_controllers/cartridge/scripts/models/CartModel.js"}
    ]
} 

This sample shows a typical GET request retrieving a list of Breakpoints resource. The response has HTTP status code 200, which indicates resources were found and are contained in response body. The response contains the "Content-Type" header, which is set to "application/json" plus the charset definition ("UTF-8").

HEAD

The HEAD method is similar to the GET method but returns headers only, not content (body). The headers are identical to those of the GET request. The HEAD method is a safe method: it does not change the state of the server.

REQUEST:
HEAD /s/-/dw/debugger/v1_0/breakpoints HTTP/1.1
Authorization: Basic YWRtaW46RGVtYW5kd2FyZTEh
x-dw-client-id: DebuggerTest
Accept: application/json

RESPONSE:
HTTP/1.1 204 NO CONTENT
Content-Length: 67
Content-Type: application/json; charset=UTF-8