Marshmellow

1.0.3

A simple networking SDK for DevRev assignment.
jatinm11/Marshmellow

What's New

2024-02-15T13:54:19Z

Marshmellow

A simple networking SDK for DevRev assignment.

Marshmellow is a very basic library that is built on top of apple's URLSession()
The main building blocks of this sdk are following 2 classes:-

public class MellowRequestBuilder (Expand)
This class is responsible for building URL requests based on provided parameters.

Key parameters include:

- init: Initializes a request builder with base URL, path, and optional parameters.
- Methods to set various request attributes such as method, path, scheme, headers, and parameters.
- buildRequest(): Constructs a URL request based on the provided parameters and returns it along with any potential errors.

        let builder = MellowRequestBuilder(
          baseURL: URL(string: urlString),
          path: requestEndpoint,
          method: method,
          scheme: scheme,
          headers: headers
      )
public class Marshmellow (Expand)
This class conforms to the MellowNetworkProtocol protocol and provides implementation for making network requests. It includes methods to set the key decoding strategy and make requests using the provided builder.

        Marshmellow().makeRequest(with: builder, type: T.self, completion: completion)

Combining the above 2 classes we get :-

let marshmellow = Marshmellow()
let builder = MellowRequestBuilder(baseURL: baseURL, path: "/api/resource")
    .set(method: .get)
    .set(headers: ["Authorization": "Bearer token"])

marshmellow.makeRequest(with: builder, type: MyResponse.self) { result in
    switch result {
    case .success(let response):
        // Handle successful response
    case .failure(let error):
        // Handle error
    }
}

That's it! 🥂

P.S - This was only built for the assignment purpose and in no way is a complete library and has huge scope of improvements 😬

P.P.S - I hope you love eating Marshmellows 😉

Description

  • Swift Tools 5.9.0
View More Packages from this Author

Dependencies

  • None
Last updated: Fri Oct 18 2024 23:39:29 GMT-0900 (Hawaii-Aleutian Daylight Time)