How to create a local server that accepts a redirect URI and then sends a message to my app

I've created a library for the Spotify web API. Part of the authorization process is opening a URL in the browser where the user is asked to login with their Spotify account and grant my application access to their account. After the user logs in and authorizes my application, Spotify will redirect to a redirect URI that I specify (it could even be localhost), with an authorization code in the query parameters.

I need to create a simple local server that accepts this redirect link and then sends a message back to my application containing the full URL, including the query parameters.

How do I create a simple HTTP server that can do this?

I'm completely new to web programming, so I may even be using the wrong vocabulary.

When creating an iOS or macOS app, I could just register a custom URL scheme for my app that accepts the redirect URI, but there are other cases, such as when I'm running unit tests or using the library in a playground (thanks, Xcode 12) where this is not possible.