How to join the result of multiple http requests

I try to create a single text by joining the result of multiple requests.

A small library application lists the author of a book. Using the Openlibrary Books API information about the authors is queried. But instead of listing the author name, they redirect using identifiers.

How to do multiple requests and join the results in a single text property?

Reading the documentation and examples, I thought it would be possible to use join for that. For each element a value “function” can be provided. I couldn’t figure out how to implement it.

I also tried to create a lambda function that returned a string value. But that yields the error:

 valid 'target' found for 'type' option 'target'. Unexpected 'target':
 	- expected:  'descriptor'
 	- but found: 'none'

The first request looks like this:

let $'ISBN Informatie' = ^ $'res'.'content' => call 'unicode'::'import' with ( $'encoding' = "UTF-8" ) => parse as JSON => decorate as {
	'title': text
	'covers': list integer
	'authors': list {
		'key': text
	}
}

Maybe call http?

'Auteur' = $'ISBN Informatie'.'authors' => join separator: ( ", " ) ( => call 'network'::'http'
	(
		$'server'         = "https://openlibrary.org"
		$'path'           = list ( $ .'key', ".json" ) => join ( )
		$'authentication' = unset
		$'request'        = new (
			'method' = option 'get'
		)
	)

It is easier to invert the operations, first perform the http requests:

let $'ISBN Informatie' = ...
let $'ISBN Authors' as list 'network'/'network response' = walk $'ISBN Informatie'.'authors' as $ => switch true => <http-request> (
  | value as $ => create $
  | error => no-op
)

With the list of http responses, you can perform the join:

let $'Authors' = $'ISBN Authors' => join separator: ( ", " ) ( $ .'content' => => call 'unicode'::'import' with ( $'encoding' = "UTF-8" ) )
1 Like

Thanks @erommen for the offline help :).
The solution is the walk the authors and create text values:

let $'Auteurs' as list text = walk $'ISBN Informatie'.'authors' as $ => switch true => call 'network'::'http' with (
	$'server'         = "https://openlibrary.org"
	$'path'           = list ( $ .'key', ".json" ) => join ( )
	$'authentication' = unset
	$'request'        = new (
		'method' = option 'get'
	)
) (
	| value as $ => switch $ .'status' => less-than ( 400 ) (
		| true => create $ .'content' => call 'unicode'::'import' with ( $'encoding' = "UTF-8" ) => parse as JSON => decorate as {
			'name': text
		} .'name' || throw "Snap het resultaatbericht niet"
		| false => no-op
	)
	| error => no-op
)

Then the result can be joined and assigned to a property:

'Auteur' = $'Auteurs' => join separator: ( ", " ) ( )