A
A
Alexander Pankov2021-05-31 11:58:30
API
Alexander Pankov, 2021-05-31 11:58:30

How to write api on Bitrix to work with node.js frontend\mobile api?

Hello, there is a site on Bitrix, the latest version of the core, the Start edition
80% of the business logic is written in d7
has its own admin panel, 20 people work in it
/bitrix, they look only to write
all the goods through parsers / imports, etc.
work with orders through self-written crm

We decided to make a mobile application, we need api, in connection with this, we decided to move the front-end to node.js + ssr, now some of the templates have already been translated with mock data

it’s time to write api for the front on node.js and for mobile applications, hence the question, please tell me links or repositories, sites with good practices, how is it better to organize everything in Bitrix, write, what constants to set, etc.? any info would be useful, from folder structure to nginx setup?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2021-05-31
Madzhugin @Suntechnic

Well, perhaps we can offer 2 approaches:
1 Use new ajax components, ie. write your own components in which to implement business logic and use the built-in mechanism to access them from the front. Here is a short article: https://verstaem.com/ajax/new-bitrix-ajax/
2 It's stupid to write api scripts in the forehead. Just scripts that simply use the internal API of the project, and already implement all the logic in this internal API.
The scripts themselves turn out something like this:

<?
require('.prolog.php');
// добавляем в избранное
  $favorites = \Model\Favorites::getInstance();
if ($_REQUEST['add']) {
  
  $favorites->add2Fav(intval($_REQUEST['add']));
} elseif ($_REQUEST['remove']) {
  $favorites->remove2Fav(intval($_REQUEST['remove']));
} elseif (strlen(trim($_REQUEST['note'])) && $_REQUEST['fav']) {
  $favorites->note2Fav(intval($_REQUEST['fav']),trim($_REQUEST['note']));
}

$arResult['appdata']['user'] = \Model\User::getInstance()->getData();

require('.epilog.php');

The first approach is stylish, fashionable, youthful, but there is nothing criminal in the second, as it seems to me.
In the end, I want to get 2 turnips that do not know anything about each other and communicate via api generated by the same Swagger

It's great to have a budget for something like this.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question