当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - Multiple rest api calls needed to render a page. How to make single api call like graphql - facebook? Any open source available like graphql?

问题描述:

Example

I am going to display Order Details

List of rest api

 Order List [{o_id:1,o_date:'',o_amt:100},...]

url/Orders

Order Item [{i_id:1,i_quantity:10,i_unit_price:5,o_id:1},...]

url/Orders/{Orderid}

Item Description {i_id:1,i_description:'description'}

url/Item/{Itemid}

----------------------------------

| | order |

|orderlist | & |

| | item description |

----------------------------------

Left side i select order I need two api calls for update my page.

This is just for example like this i need to multiple api call.

Any opensource like graphql

enter link description here

网友答案:

Maybe you can try https://github.com/ericclemmons/react-resolver

In the readme it once claimed: when graphQL is out you should be able to make a smooth transiton.

They removed that but is still is a way to fetch async data on a component level.

网友答案:

You can take a look on Breeze.js. It requires proper implementation of OData protocol on the server side, but at the end you will be able to combine related calls into single one with similar query:

// Query for Order with ID 42,
// expanded to include related Item data.
// the result will contain both order and item data
var query = EntityQuery.from('Orders')
   .where('OrderId', 'eq', 42)
   .expand('Item');

Either way any solution with features similar to GraphQl will require following a protocol on client and the server, keep this in mind when you consider particular library/framework.

分享给朋友:
您可能感兴趣的文章:
随机阅读: