mcrumm

mcrumm

Phoenix Core Team

ReqSandbox - Ecto SQL Sandbox requests for external HTTP clients

Photo of a toy truck in a sandbox
Photo by Takeshi Morisato on Unsplash

Req plugin for Phoenix.Ecto.SQL.Sandbox.

ReqSandbox simplifies making concurrent, transactional requests to a Phoenix server. Just before making a request, the sandbox metadata is applied via the specified request header. If there is no metadata available, then ReqSandbox creates a new sandbox session and saves the metadata for future requests. This is mostly useful in client test environments to ensure logical isolation between concurrent tests.

Usage

The Ecto SQL Sandbox Usage Guide included in the docs is a Livebook with an interactive demonstration of all the sandbox features.

Mix.install([
  {:req, "~> 0.3.0"},
  {:req_sandbox, "~> 0.1.0"}
])

req = Req.new(base_url: "http://localhost:4000" |> ReqSandbox.attach()

Req.post!(req, url: "/api/posts", json: %{"post" => %{"msg" => "Hello, world!"}}).body
# => %{"data" => %{"id" => 2, "msg" => "Hello, world!"}}

ReqSandbox.delete!(req)
# => "BeamMetadata (g2gCZAACdjF0AAAAA2QABW93bmVyWGQAInZ2ZXMzM2o1LWxpdmVib29...)"

Audience

If you are writing HTTP clients in Elixir to communicate with Phoenix/Plug + Ecto services, then this package is for you! Sandboxing client requests is an effective way to provide developers with an integration environment that can be operated concurrently while maintaining logical isolation between development sessions.

First Post!

ityonemo

ityonemo

im surprised this doesn’t just add $callers into the header, that way the http request also has access to mox, and whatever else in the ecosystem gets that kind of concurrency support, in stead of just ecto

Most Liked

LostKobrakai

LostKobrakai

There’s no long running pid to set $callers to for the phoenix sandbox. It’s meant to work for e2e tests for tools, which might not even run on the beam, which checkout and checkin db connections statelessly as far as the beam is concerned.

mcrumm

mcrumm

Phoenix Core Team

v0.1.2 (2022-12-22)

  • Removes POST body content before making the sandbox request.

  • Adds missing content-length header on the sandbox request.

  • Adds ReqSandbox.token/0 to fetch the current token if it exists.

Where Next?

Popular in Announcing Top

pkrawat1
Hey guyz We at @aviabird are working on a payment library in elixir/phoenix. We are targeting March 2018 to add 56 Gateways to it. Have...
New
kip
ex_cldr provides localisation and internationalisation support based upon the data from the Unicode CLDR project. Unicode released CLDR ...
407 13366 120
New
devonestes
Introducing assertions, the library that helps you write really great test assertions! GitHub: GitHub - devonestes/assertions: Helpful a...
New
kip
Image is an image processing library for Elixir. It is based upon the fabulous vix library that provides a libvips wrapper for Elixir. I...
622 19610 194
New
trisolaran
Hi! :waving_hand: I would like to present LiveSelect, a little library that I wrote to easily add a dynamic selection input to your LV f...
198 11283 107
New
martinthenth
Hello everybody :wave: Recently, some of my colleagues talked about database ids and uuids and their problems, and I remembered the pain...
New
MRdotB
I needed to reuse React components from my Chrome extension in my Phoenix/LiveView backend. I noticed that for Svelte/Vue, there are live...
New

Other popular topics Top

Qqwy
Update: How to use the Blogs & Podcasts section You can post links to your blog posts or podcasts either in one of the Official Blog...
3271 131117 1222
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1144 55125 245
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New

We're in Beta

About us Mission Statement