V
V
valentine112016-10-25 14:44:56
PHP
valentine11, 2016-10-25 14:44:56

How to work with API written in php from node.js?

Our project has an API written in php for working with a database.
In order to prepare the database for testing, the programmers have added several methods so that we (the testers) do not write the queries themselves, but pull the API methods.
Run example:
Entry point URL " https://api.mystend.domain.zone/jsonRpc "
Query according to JsonRpc standard.
We write tests in js.
If for direct requests I would use node-mysql, then here I have no idea from which side to approach the task, which package to download, and whether it is even possible to implement in js work with API methods written in php. I hear about Json-rpc for the first time.
Tell me, pliz, where to start?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
_
_ _, 2016-10-25
@valentine11

JsonRpc is just a buzzword for under-REST (well, or re-REST) ​​over http.
Install superagent via npm and go:

request
  .get('https://api.mystend.domain.zone/jsonRpc')
  .send({ query: 'dogById', id: '13' }) /* тут вот некий объект, описывающий запрос согласно спецификации, которую вам должны предоставить разработчики вашего "JsonRpc" */ 
  .set('X-API-Key', 'foobar') // Ну и заголовочки (авторизация там может или еще что)
  .set('Accept', 'application/json')
  .end(function(err, res) { // Тут ответ этого самого JsonRpc
    expect(res.dogName).toEqual('Brownie');
  });

V
valentine11, 2016-10-27
@valentine11

The decision from Alexander Marchenko is correct, the error was because the stand was assembled with the wrong branch ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question