Skip to content

Commit 387bc3e

Browse files
committed
feat: use jsonplaceholder api instead of local api
1 parent a55b4d9 commit 387bc3e

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

Examples/DeleteJSON/DeleteJSON.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ struct DeleteJSON {
99
let httpClient = HTTPClient.shared
1010

1111
do {
12-
var request = HTTPClientRequest(url: "http://localhost:8080/todos/1)")
12+
var request = HTTPClientRequest(url: "https://jsonplaceholder.typicode.com/todos/1")
1313
request.method = .DELETE
1414

1515
let response = try await httpClient.execute(request, timeout: .seconds(30))

Examples/PostJSON/PostJSON.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,22 @@ import NIOCore
44
import NIOFoundationCompat
55

66
struct Todo: Codable {
7-
var id: Int
8-
var name: String
7+
var id: Int?
8+
var userId: Int
9+
var title: String
910
var completed: Bool
1011
}
1112

1213
@main
1314
struct PostJSON {
1415
static func main() async throws {
1516
let httpClient = HTTPClient(eventLoopGroupProvider: .singleton)
16-
let payload = Todo(id: 1, name: "Test Todo", completed: false)
17+
let payload = Todo(userId: 1, title: "Test Todo", completed: false)
1718

1819
do {
1920
let jsonData = try JSONEncoder().encode(payload)
2021

21-
var request = HTTPClientRequest(url: "http://localhost:8080/todos")
22+
var request = HTTPClientRequest(url: "https://jsonplaceholder.typicode.com/todos")
2223
request.method = .POST
2324
request.headers.add(name: "Content-Type", value: "application/json")
2425
request.body = .bytes(jsonData)

Examples/PutJSON/PutJSON.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,21 @@ import NIOFoundationCompat
55

66
struct Todo: Codable {
77
var id: Int
8-
var name: String
8+
var userId: Int
9+
var title: String
910
var completed: Bool
1011
}
1112

1213
@main
1314
struct PostJSON {
1415
static func main() async throws {
1516
let httpClient = HTTPClient(eventLoopGroupProvider: .singleton)
16-
let payload = Todo(id: 1, name: "Test Todo", completed: true)
17+
let payload = Todo(id: 1, userId: 1, title: "Test Todo", completed: false)
1718

1819
do {
1920
let jsonData = try JSONEncoder().encode(payload)
2021

21-
var request = HTTPClientRequest(url: "http://localhost:8080/todos/\(payload.id)")
22+
var request = HTTPClientRequest(url: "https://jsonplaceholder.typicode.com/todos/\(payload.id)")
2223
request.method = .PUT
2324
request.headers.add(name: "Content-Type", value: "application/json")
2425
request.body = .bytes(jsonData)

0 commit comments

Comments
 (0)