xp-forge / xp-forge/rest-client

Asynchronous invocation

Open
#25 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement help wanted
Dominant language
PHP
Stars
0
Forks
1
PR merge metrics
No merged PRs in 30d

Description

If used inside a single-threaded xp-forge/web web application, waiting will block the entire server. We should also have an asynchronous method to execute requests and wait for them.

Blocks server until API call returns

Current functionality

function($req, $res) use($endpoint) {
  $user= $endpoint->resource('/users/me')->get()->value();
  
  $res->answer(200);
  $res->write('Hello '.$user['displayName'], 'text/plain');
}
Asynchronous handler function

Idea: Defer reading from request until any of RestResponse's methods are called, add await():

function($req, $res) use($endpoint) {
  $user= (yield $endpoint->resource('/users/me')->get()->await())->value();
  
  $res->answer(200);
  $res->write('Hello '.$user['displayName'], 'text/plain');
}

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the current request flow described in the issue, especially RestResponse methods and the endpoint resource('/users/me')->get()->value() call. Compare it with the proposed generator-based await() handler and determine how deferred reading should interact with the response methods. Done means asynchronous invocation can avoid blocking a single-threaded xp-forge/web server while preserving the existing response behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
api, backend
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.