Skip to content

Simple network request building library so I don't need to do this more than once

License

Notifications You must be signed in to change notification settings

pschuette22/SwiftRequestBuilder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SwiftRequestBuilder

Build and test HTTP requests with concise, compile safe code.

Builder syntax

let request = URLRequest(SimpleTestBody.self) {
    HTTPMethod(.post)
    Header("header1", value: "value")
    URL(string: "https://google.com")!
    QueryItem("query", value: 1)
    Body(SimpleTestBody(
        hello: "Hello!",
        world: 1,
        isExcited: true
    ))
}

Factory Syntax

let request = RequestFactory()
    .with(httpMethod: .post)
    .with(baseURL: URL(string: "https://google.com")!)
    .with(header: "header1", equaling: "value")
    .with(
        httpBody: SimpleTestBody(
            hello: "Hello!",
            world: 1,
            isExcited: true
        )
    )
    .build()

Test it

let blueprint = Blueprint(
    bodyType: SimpleTestBody.self,
    method: HTTPMethod.post,
    url: "https://google.com",
    headers: ["header1": "value"],
    body: SimpleTestBody(
        hello: "Hello!",
        world: 1,
        isExcited: true
    ),
    documentURL: nil
)

try assertRequest(request, matches: blueprint)

About

Simple network request building library so I don't need to do this more than once

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages