# HTTP macro

**URL:** <https://forums.swift.org/t/http-macro/84622>\
**Category:** Macros\
**Created:** [February 8, 2026, 11:44am UTC](https://forums.swift.org/t/http-macro/84622 "2026-02-08T11:44:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![romanindermuehle](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/romanindermuehle/32/35940_2.png) [@romanindermuehle](https://forums.swift.org/u/romanindermuehle)\
**Post date:** [February 8, 2026, 11:44am UTC](https://forums.swift.org/t/http-macro/84622/1 "2026-02-08T11:44:48Z")

</div>

Recently, I had the idea to create a Swift HTTP macro that would streamline requests.

This is how I imagine it to work:

```swift
@HTTPClient(
    baseURL: "https://api.example.com",
    contentType: "application/json",
    useCookies: true
)
struct MyAPIClient {
    @Endpoint(method: .GET, path: "/users")
    func getUsers(queryParams: [String: String] = [:], headers: [String: String] = [:], completion: @escaping (Data?, Error?) -> Void)

    @Endpoint(method: .POST, path: "/users", contentType: "application/json")
    func createUser(body: Data, headers: [String: String] = [:], completion: @escaping (Data?, Error?) -> Void)

    @Endpoint(method: .POST, path: "/users", contentType: "application/x-www-form-urlencoded")
    func createUserForm(body: [String: String], headers: [String: String] = [:], completion: @escaping (Data?, Error?) -> Void)
}

```

Then the goal would be to make it work for Apple, Linux, and WebAssembly.

Since I have never created a Swift macro, I’m not sure if it makes sense to use a macro for that or if it would be better to use the Swift OpenAPI generator instead. What do you think?

---

<div class="post-metadata">

**Author:** ![t089](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/t089/32/40449_2.png) [@t089](https://forums.swift.org/u/t089)\
**Post date:** [February 8, 2026, 1:11pm UTC](https://forums.swift.org/t/http-macro/84622/2 "2026-02-08T13:11:53Z")

</div>

Seems like a viable idea: [GitHub - joshuawright11/papyrus: A type-safe HTTP client for Swift.](https://github.com/joshuawright11/papyrus)

---

<div class="post-metadata">

**Author:** ![romanindermuehle](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/romanindermuehle/32/35940_2.png) [@romanindermuehle](https://forums.swift.org/u/romanindermuehle)\
**Post date:** [February 8, 2026, 2:51pm UTC](https://forums.swift.org/t/http-macro/84622/3 "2026-02-08T14:51:47Z")

</div>

Thanks for your reply @t089.

Oh, I remember seeing that one before! Unfortunately, it doesn’t play nice with WebAssembly. Also, when I peeked at the open PR and issues, it seems like the package hasn’t been making much headway lately. But, since I’m new to macros and eager to create something myself, I imagine it would take some time. What do you think?

---

<div class="post-metadata">

**Author:** ![t089](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/t089/32/40449_2.png) [@t089](https://forums.swift.org/u/t089)\
**Post date:** [February 8, 2026, 5:03pm UTC](https://forums.swift.org/t/http-macro/84622/4 "2026-02-08T17:03:57Z")

</div>

By no means feel discouraged, take a look at the existing repos and try to improve on them. Would be great to have something that plays nice with Linux and web assembly! Absolutely!

You _could_ take a look at the open api generator runtime package. They have a “transport” protocol which all the http client “backends” implement. This is a good way to make your lib extensible to different platforms / http client implementations.

They should have used `FoundationEssentials.URL` though ☹

> <https://github.com/apple/swift-openapi-runtime/blob/main/Sources/OpenAPIRuntime/Interface/ClientTransport.swift>

---

<div class="post-metadata">

**Author:** ![romanindermuehle](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/romanindermuehle/32/35940_2.png) [@romanindermuehle](https://forums.swift.org/u/romanindermuehle)\
**Post date:** [February 16, 2026, 10:21pm UTC](https://forums.swift.org/t/http-macro/84622/5 "2026-02-16T22:21:39Z")

</div>

Thanks for sharing, that’s a good idea.

I’m wondering how hard it will be to make it mockable?

At the moment I’m thinking what would be better to create a http macro or just create an issue for the OpenAPI generator to add WebAssembly support. What do you think?
