PHPackages                             ebredy/apichainning - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. ebredy/apichainning

ActiveLibrary[API Development](/categories/api)

ebredy/apichainning
===================

API Chainning

1.1.9(6y ago)0154MITPHPPHP &gt;=5.5.0

Since Jan 12Pushed 6y ago2 watchersCompare

[ Source](https://github.com/Yestime/apiChainning)[ Packagist](https://packagist.org/packages/ebredy/apichainning)[ RSS](/packages/ebredy-apichainning/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (2)Versions (15)Used By (0)

PHP SDK for REST API Multiple-Request Chaining
==============================================

[](#php-sdk-for-rest-api-multiple-request-chaining)

Currently under development.

For more examples of chaining with Mock APIs - visit

REST API Multiple-Request Chaining
==================================

[](#rest-api-multiple-request-chaining)

One of the challenges in using RESTful APIs driven by Hypermedia, as well as pulling in numerous and extensive microservices is the requirement to at times make several API calls in order to accomplish the task at hand. Today, that requires numerous HTTP calls as well, which depending on latency, can greatly slow script execution.

REST API Multiple-Request Chaining is a technique that groups numerous RESTful API calls together in a single HTTP request.

For example, as shown below, instead of having to do GET calls to `/users/5` and then `/messages/?userId=5` you could instead send a chain to a resource such as `/multirequestchain` that would handle the multiple calls for you.

REST API Multiple-Request Chaining is setup to allow for conditional calls, as well as provides back only the data you need (instead of all the data that would be returned from each call). This can also be used as a technique for data collection similar to that of GraphQL where instead of embedding objects as models, you're able to make numerous calls at once and get back only the data you request.

A Simple REST API Multiple-Request Chain
----------------------------------------

[](#a-simple-rest-api-multiple-request-chain)

Each chain is made of 5 components, all required:

ComponentDescriptionExampledoOnDoOn provides the condition on which the call should be performed. Options include "always", a logical if statement `($body.user.firstName == 'Jim')` or an HTTP status code (with \* being a wildcard).4\*\*urlThe complete path (including querystring) for the call being performed/users/?lastName=SmithmethodThe HTTP method you wish to use to perform the call (such as GET, POST, etc)getdataA string or JSON Object of the data you wish to send via the call (typically with POST, PUT, PATCH, DELETE){ "firstName" : "Jim", "lastName" : "Smith" }returnThe data (as an array) you wish to have returned. If you wish for all data to be returned, use boolean "true" or if you wish for no data to be returned, use boolean "false.". Also, you can use JSONPath expressions, which are described [here](https://github.com/FlowCommunications/JSONPath)\["firstName", "email", "\_links"\]headersRequest headers (as an array). This field is optional.\["Connection" =&gt; "keep-alive", "Accept-Encoding" =&gt; "gzip, deflate, br"\]A simple request where you want to retrieve a user's messages, but first need to make a call to the `/users` resource to obtain the information may look like this:

```
[
  {
    "doOn": "always",
    "url": "/users/5",
    "method": "get",
    "data": {},
    "return": "$.*._links"
  },
  {
    "doOn": 200,
    "url" : "$body._links.messages",
    "method": "get",
    "data": {
        "emailAddress": "$body.email"
    },
    "headers": {
        "Cache-Control": "no-cache",
        "Connection": "keep-alive"
    }
    "return": true,
  }
]

```

Multiple Conditional Calls
--------------------------

[](#multiple-conditional-calls)

REST API Multiple-Request Chaining works in chronological order, with each call being considered the next highest priority, or the next natural step in the process.

The `doOn` specifies whether or not the call should be executed based on the previous call's response, or whether it should be skipped for another call that contains a `doOn` that matches the previous HTTP status code, applies a logical IF statement that returns true, or is specified as "always." In the event that no suitable match is found in the layer of the chain it is currently operating in, the chain will consider this an error and exit - returning back all the data up and including the last call that was attempted.

For example, in our previous chain - IF the `/users/5` call returned a 404, the chain would have exited, providing you the details of that call, but **NOT** attempting the next call `$body._links.messages` as it required a status code of 200.

You can also layer multiple conditional calls by placing them in arrays, creating a new layer in the process. However, once the chain reaches the end of its child layers, it will exit - **NOT** iterating through the remaining parent layers.

```
[
  {
    "doOn": "always",
    "url": "/users/5",
    "method": "get",
    "data": {},
    "return": [
        "email", "_links"
    ]
  },
  [
    {
      "doOn": 200,
      "url" : "$body._links.messages",
      "method": "get",
      "data": {
          "emailAddress": "$body.email"
      },
      "return": true,
    },
    {
      "doOn": "4*|5*",
      "url" : "/users",
      "method": "post",
      "data": {
        "firstName": "Jim",
        "lastName": "Smith",
        "emailAddress": "jim.smith@domain.ext"
      },
      "return": true,
    },
    [
      {
        "doOn": "201",
        "url": "$headers.link",
        "method": "get",
        "data": {},
        "return": [
            "email", "_links"
        ]
      },
      {
        "doOn": 200,
        "url" : "$body._links.sendMessage",
        "method": "post",
        "data": {
          "to": "$body.email",
          "subject": "Welcome $body.firstName",
          "body": "Hello and welcome to our site!"
        },
        "return": true,
      }
    ]
  ]
]

```

Complex IF Statements
---------------------

[](#complex-if-statements)

The `doOn` property accepts an HTTP Status Code, "always" as a string, or a conditional logical IF statements:

##### Simple Equal/ Not Equal

[](#simple-equal-not-equal)

LogicExampleMeaning==$body.firstName == 'Jim'firstName in Body response is **equal** to Jim!=$body.firstName != 'Jim'firstName in Body response is **not equal** to Jim&gt;=$body.age &gt;= 10age in Body response is **greater than or equal** to 10&lt;=$body.age &lt;= 10age in Body response is **less than or equal** to 10##### AND OR STATEMENTS

[](#and-or-statements)

LogicExampleMeaning&amp;&amp;$body.firstName != 'Jim' &amp;&amp; $body.age &gt;= 10First condition **AND** second condition must be matched||$body.firstName != 'Jim' || $body.age &gt;= 10Match **EITHER** condition##### REGULAR EXPRESSIONS

[](#regular-expressions)

LogicExampleMeaningregex()regex('/\[a-z\]/i', $body.firstName)**Match** a regular expression!regex()regex('/\[a-z\]/i', $body.firstName)Does **not match** regular expression### Complex Example 1:

[](#complex-example-1)

```
[
  {
    "doOn": "always",
    "url": "/users/5",
    "method": "get",
    "data": {},
    "return": [
        "firstName", "lastName", "email", "_links"
    ]
  },
  {
    "doOn": "($body.firstName == "Jim" && $body.lastName == "Smith") || regex('/Jim/i', $body.email)",
    "url" : "$body._links.messages",
    "method": "get",
    "data": {
        "emailAddress": "$body.email"
    },
    "return": true,
  }
]

```

### Complex Example 2:

[](#complex-example-2)

```
[
        {
            "doOn": "always",
            "url": "https://www.tn-apis.com/catalog/v1/events/${global.eventId}",
            "method": "get",
            "name": "api:ticketnetwork:catalog:events",
            "globals": {},
            "data": {},
            "headers": {
                "Authorization": "Bearer 9750bc1c-178d-36f7-802b-b6b9ebcb3efd",
                "x-listing-context": "website-config-id=3551",
                "Accept": "application/json"
            },
            "return": {
                "latitudeFromTN": "geoLocation.latitude",
                "longitudeFromTN": "geoLocation.longitude",
                // custom php callbacks are created with
                //and called by prefixing them with callback.  An addition any php function
                //can be called using the prefix "callback_"
                "dateFromTN": "${callback_extract_date(date.datetime,0,10)}",
                "timeFromTN": "${callback_format_time(date.text.time)}",
                "venueId": "venue.id",
                "countryFromTN": "country.alphaCode",
                "stateFromTN": "stateProvince.text.abbr",
                "eventNameFromTN": "text.name",
                "cityFromTN": "city.text.name",
                "isResult": "${callback_has_results(venue.id)}"
            }
        },
        {
            "doOn": "200",
            "url": "https://www.way.com/way-service/home/suggestions",
            "method": "post",
            "name": "api:way:suggestions",
            "data": {
                "latitude": "$body.latitudeFromTN",
                "longitude": "$body.longitudeFromTN",
                "searchQuery": "TNvenue${body.venueId}WAY ${body.dateFromTN} ${body.timeFromTN}",
                "serviceType": "PARKING"
            },
            "headers": {
                "Content-Type": "application/json"
            },
            "return": {
                "wayEventId": "response[0].listingIdentifier",
                "wayVenueId": "response[0].venueId",
                "wayLatitude": "response[0].latitude",
                "wayLongitude": "response[0].longitude",
                "wayAddressLine1": "response[0].addressBo.addressLine1",
                "wayCity": "response[0].addressBo.city.cityName",
                "wayState": "response[0].addressBo.state.stateCode",
                "wayZipcode": "response[0].addressBo.zipcode.zipcode",
                "wayCountry": "response[0].addressBo.country.countryName",
                "wayHasResult": "${callback_has_results(response)}"
            }
        },
        {
            "doOn": "$body.wayHasResult == true",
            "url": "https://www.way.com/way-service/parking/search",
            "method": "post",
            "name": "api:way:parking:search:events",
            "data": {
                "eventId": "$body.wayEventId",
                "reqType": "jump",
                "venueId": "$body.wayVenueId",
                "latitude": "$body.wayLatitude",
                "longitude": "$body.wayLongitude",
                "pageIndex": 1,
                "parkingFilter": {
                    "nearBy": "Event"
                },
                "numberOfRecords": 10
            },
            "headers": {
                "Content-Type": "application/json"
            },
            "return": true
        }
]

```

### Complex Example 3(using headers/ accept :application/xml):

[](#complex-example-3using-headers-accept-applicationxml)

```
 [
        {
            "doOn": "always",
            "url": "https://link-search.api.cj.com/v2/link-search?website-id=9007016&link-type=banner&advertiser-ids=joined",
            "method": "get",
            "name": "api:cjmanual:v2:linksearch",
            "globals": {},
            "data": {},
            "headers": {
                "Authorization": "Bearer 351q6ebydq98pwv1fttxcgpsqs",
                "Accept": "application/xml"
            },
            "return": true
        }
    ]

```

Responses
---------

[](#responses)

Because conditional chaining and errors are possible when using REST API Multiple-Request Chaining, the response object needs to return three primary properties:

PropertyTypeDefinitioncallsReqestedintegerThe number of conditionally applicable calls requested in the chain - this will not necessarily be the total number of calls in the requestcallsCompletedintegerThe number of calls that were completed successfully. This helps indicate an error IF the chain had multiple calls, but a condition could not be matched and therefore caused the chain to exitresponsesarraythe list of applicable responses to the API chain calls that were performed, including the last call that could either be executed either because the chain was completed or exited due to being unable to meet a necessary condition.Within the responses array, each call object needs to include:

PropertyDefinitionExampleurlthe full path of the call that was attempted/users?firstName=Jimmethodthe method that was used to make the callgetstatusthe HTTP status code the call returned200responsea response object containing the headers (as an object) and the body (as an object or string depending on content-type)"headers" : { "content-type" : "application/json" }, "body" : { "user" : { "firstName" : "Jim" } }```
{
  "callsRequested" : 2,
  "callsCompleted" : 2,
  "responses" : [
    {
      "url" : "/users/5",
      "method" : "get",
      "status" : 200,
      "response" : {
        "headers" : {},
        "body" : {
          "email": "user@user.ext",
          "_links": {}
        }
      }
    },

    {
      "url" : "/messages/?userId=5",
      "method" : "get",
      "status" : 200,
      "response" : {
        "headers" : {},
        "body" : {}
      }
    }
  ]
}

```

FAQs
----

[](#faqs)

### How do you send headers with REST API Multiple-Request Chaining?

[](#how-do-you-send-headers-with-rest-api-multiple-request-chaining)

Headers are sent as they always have been, and will automatically be applied to each of the calls requested in the chain. At this time, REST API Multiple-Request Chaining does not support the ability to send specific headers for each call independently - however, if needed, this may certainly be added in the future.

### How does this vary from IO State Driven APIs

[](#how-does-this-vary-from-io-state-driven-apis)

REST API Multiple-Request Chaining is designed specifically for RESTful APIs utilizing hypermedia over a static or cached state file. This allows for the available paths to be truly dynamic based on the individual calls within the chain, and also prevents the need to make multiple requests to obtain the IO State or available OPTIONS. REST API Multiple-Request Chaining is also designed to expand beyond just the use of a primary key, letting you pull in information from the headers and body of the previous call when performing an action on the next chain. Each link/ call is also conditional, meaning you can specify when that link should be called, and receive the appropriate error response upon a link/ call failure. For more you can see Owen's IO State implemention [here](https://github.com/orubel/grails-api-toolkit-docs/wiki/API-Chaining).

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor1

Top contributor holds 53% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~15 days

Recently: every ~0 days

Total

12

Last Release

2514d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5d305896d9c98f29dedfbf6b65f0699ae80ab2a89b20d93deb21ce706325976f?d=identicon)[ebredy](/maintainers/ebredy)

---

Top Contributors

[![Stexxe](https://avatars.githubusercontent.com/u/7986337?v=4)](https://github.com/Stexxe "Stexxe (35 commits)")[![ebredy](https://avatars.githubusercontent.com/u/3597114?v=4)](https://github.com/ebredy "ebredy (25 commits)")[![mikestowe](https://avatars.githubusercontent.com/u/414978?v=4)](https://github.com/mikestowe "mikestowe (6 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ebredy-apichainning/health.svg)

```
[![Health](https://phpackages.com/badges/ebredy-apichainning/health.svg)](https://phpackages.com/packages/ebredy-apichainning)
```

###  Alternatives

[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/common-protos

Google API Common Protos for PHP

173103.7M50](/packages/google-common-protos)[hubspot/api-client

Hubspot API client

23414.2M16](/packages/hubspot-api-client)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
