-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrest-methods.pwn
More file actions
35 lines (30 loc) · 1023 Bytes
/
rest-methods.pwn
File metadata and controls
35 lines (30 loc) · 1023 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// rest-methods.pwn — PUT, DELETE, and PATCH against a REST resource.
//
// Demonstrates:
// * Using HTTPS_PUT / HTTPS_DELETE / HTTPS_PATCH.
// * Reading the HTTP status to confirm idempotent updates.
#include <a_samp>
#include <https_samp>
public OnGameModeInit()
{
// PUT: full replacement
https_jsonf("{\"name\":\"erick\",\"score\":100}");
https(1, HTTPS_PUT, "https://httpbin.org/anything/players/42", "", "OnRest");
// PATCH: partial update
https_jsonf("{\"score\":150}");
https(2, HTTPS_PATCH, "https://httpbin.org/anything/players/42", "", "OnRest");
// DELETE: no body
https(3, HTTPS_DELETE, "https://httpbin.org/anything/players/42", "", "OnRest");
return 1;
}
forward OnRest(index, response[], status, error);
public OnRest(index, response[], status, error)
{
if (error != HTTPS_ERROR_NONE)
{
printf("[example] req %d failed: error=%d", index, error);
return 1;
}
printf("[example] req %d status=%d", index, status);
return 1;
}