# Testing an api wrapper

**URL:** https://discourse.julialang.org/t/testing-an-api-wrapper/111140
**Category:** General Usage
**Tags:** question, testing
**Created:** [March 4, 2024, 4:42pm UTC](https://discourse.julialang.org/t/testing-an-api-wrapper/111140 "2024-03-04T16:42:05Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![knbrt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/knbrt/32/21651_2.png) [@knbrt](https://discourse.julialang.org/u/knbrt)
#### Post date: [March 4, 2024, 4:42pm UTC](https://discourse.julialang.org/t/testing-an-api-wrapper/111140/1 "2024-03-04T16:42:05Z")

</div>

Hi there, currently I’m trying to write tests for an api wrapper I created. Of course I don’t want to actually call the RestAPI during testing. Luckily I discovered [BrokenRecord.jl](https://github.com/JuliaTesting/BrokenRecord.jl) which is working nicely. But unfortunately I can’t figure out a nice way to test uploads, because

`ERROR: Request body does not match`

And with looking into what is changing, I detected the ‘body.boundary’ (with body beeing a HTTP.Forms.Form struct) is changing on each time, even if I always use the same file.

Did someone encounter that problem / situation already? Do I overlook an obvious solution (hopefully)? Are there any recommondations?

I’d be happy for every hint, comment, answers…

---

<div class="post-metadata">

### Author: ![TheCedarPrince](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thecedarprince/32/17323_2.png) [@TheCedarPrince](https://discourse.julialang.org/u/TheCedarPrince)
#### Post date: [April 28, 2024, 5:11pm UTC](https://discourse.julialang.org/t/testing-an-api-wrapper/111140/2 "2024-04-28T17:11:21Z")

</div>

Hi folks! I am reviving this question from @knbrt as I am also curious about how best to test an API when one has developed a Julia-based wrapper for that API.

Here’s an example of some Julia code I have written for my wrapper:

```julia
using IPUMS

api = IPUMSAPI("https://api.ipums.org/", Dict("Authorization" => "Your_Key"))

test_extract_definition = "test/testdata/example_extract_request.json"

res = extract_submit(api, "nhgis", test_extract_definition)

metadata, defn, msg = extract_info(api, res.number, "nhgis")

extract_list(api, "nhgis")

```

As you can see, all these commands hit the API endpoint I have provided. I don’t want to have to actually hit the API endpoint every single time I run my test suite. Any thoughts about how to handle this?

Thanks!

~ tcp 🌳

P.S. CCing @bauglir as I am curious how you do API testing with Kroki.jl (which is quite a neat package!)
