Skip to content

Releases: bpisano/NetworkKit

1.3.0

27 Oct 13:39

Choose a tag to compare

@Path macro

The @Path property wrapper is now a macro. This lets you write your path properties as let instead of var. You can also specify a custom name for the path so your property name doesn't need to exactly match the one you provided in the method macro.

@Get("/users/:id")
struct GetUser {
-    @Path
-    var id: String
+    @Path("id")
+    let userId: String
}

Response improvements

The Response type changed the data property to decodedData to improve error handling. You can now receive a 400 error from your server without NetworkKit throwing a decoding error instantly.

In the following example, the print function would never be executed because the Client would first try to decode the received data in order to populate the response.data property. However, servers tend to return a different response type when the request returns an error.

let response = try await client.perform(request)
print(response.statusCode) // never executed in case of a 400 status code

With NetworkKit 1.3.0, the decoding of the response is now performed in the Response instead of the Client.

let response = try await client.perform(request)
print(response.statusCode) // At this point, the server has returned a valid response
let data: User = try response.decodedData // Will throw a decoding error in case of a type mismatch.

You can also choose in which format you want to decode the received data.

let response = try await client.perform(request)
let errorData = try response.decodedData(as: HttpNotFoundError.self)

1.2.0

08 Oct 13:11

Choose a tag to compare

  • Added a new @Response that makes response type definition more flexible and intuitive.
  • NetworkKit now includes DocC documentation! Read it here.

Response macro

You can use the @Response macro like this:

@Get("/users/:id")
@Response(User.self) // if you want to reuse an external type
struct GetUserRequest {
    @Path
    var id: String
}

or

@Get("/users/:id")
struct GetUserRequest {
    @Response // if you want to declare the type as part of the request
    struct UserDto {
        let id: String
        let name: String
        let email: String
    }

    @Path
    var id: String
}

When used internally, the @Response macro automatically adds Decodable conformance to your response types. This replaces the previous @Get(/users, of: [Users].self) syntax.

1.1.1

28 Aug 08:34

Choose a tag to compare

  • Fixed compiling error when a request struct was public.

1.1.0

28 Jul 13:52

Choose a tag to compare

  • The type of the response is now strongly typed with the request. You can add the response type in the parameter of the http macro.
@Get('/users', of: [User].self)
struct GetUsers {
}

1.0.0

17 Jul 15:54

Choose a tag to compare

0.3.0

28 Oct 14:14

Choose a tag to compare

  • Improved logging.
  • Added Content-type header when a dictionary is passed as a request body.

0.2.0

28 Oct 13:25

Choose a tag to compare

  • Renamed Server to Client.
  • Added ServerLogger protocol. Use it to log data when a client perform a request.
  • / is no more required on the HttpRequest path property.

0.1.0

26 Aug 10:50

Choose a tag to compare

Initial release 🎉