Skip to content
CheckcraftDownload
Practical workflow

1C HTTP services: create, publish, test and debug with examples

Checkcraft is a desktop app for checking APIs and logs without code, with a free edition. Download, no sign-up →

An HTTP service turns a 1C database into a REST API for a website, a mobile app or another system. Below is the whole path: the configuration object, URL template and handler, a JSON response, publishing, the /hs/ address, testing from outside and the usual integration errors.

Checkcraft ·

Get help with your first test →

How an HTTP service is built

In the configuration under Common you add an HTTP service with a root URL such as api. Inside are URL templates like /orders/{id}, each template has GET, POST and other methods, and each method has a handler in the service module. The handler gets an HTTPServiceRequest and returns an HTTPServiceResponse.

Where to find the service after publishing

After publishing the database on a web server the service is available at http://server/publication_name/hs/root_url/template. If the address returns 404, check that HTTP services are published by default or the service is ticked in the list.

API call diagram: method and URL, headers, body, status and response body, logs and database

How to test the service from outside

Send a request with curl or an API client using a 1C account and look at the status, headers and body. Check not just the happy path: a missing id, broken JSON in the body, a request without auth. Each should return a clear code and a JSON error, not a web server page.

How to save the checks and repeat them

The service changes with the configuration, and what worked yesterday may answer differently after an update. Save requests to the service with response rules and run them after every update. That is integration regression testing.

Layers of an API call check: status, headers, body, calculations, logs, database

A handler that returns JSON

// Шаблон URL: /orders/{id}, метод GET, обработчик ЗаказGET
Функция ЗаказGET(Запрос)
    Ид = Запрос.ПараметрыURL["id"];
    Заказ = НайтиЗаказ(Ид); // ваша функция

    Если Заказ = Неопределено Тогда
        Возврат ОтветJSON(404, Новый Структура("error", "order not found"));
    КонецЕсли;
    Возврат ОтветJSON(200, Заказ);
КонецФункции

Функция ОтветJSON(Код, Значение)
    Запись = Новый ЗаписьJSON;
    Запись.УстановитьСтроку();
    ЗаписатьJSON(Запись, Значение);
    Ответ = Новый HTTPСервисОтвет(Код);
    Ответ.Заголовки.Вставить("Content-Type", "application/json; charset=utf-8");
    Ответ.УстановитьТелоИзСтроки(Запись.Закрыть(), "UTF-8", ИспользованиеByteOrderMark.НеИспользовать);
    Возврат Ответ;
КонецФункции

Content-Type with charset and a body without a BOM spare the client half of the parsing problems. Return errors as JSON with the right code too, not as text.

Testing the service with curl

# GET существующего и несуществующего заказа
curl -i -u "Обмен:пароль" http://erp.example.local/trade/hs/api/orders/5001
curl -i -u "Обмен:пароль" http://erp.example.local/trade/hs/api/orders/999999

# POST с JSON
curl -i -u "Обмен:пароль" -H "Content-Type: application/json" \
  --data '{"sku":"A-1","qty":2}' http://erp.example.local/trade/hs/api/orders

# без авторизации: ожидаем 401, а не страницу веб-сервера
curl -i http://erp.example.local/trade/hs/api/orders/5001

The address is the web server publication name, the /hs/ segment, the service root URL and the template. More request examples in curl POST with JSON.

What to check in an HTTP service

CheckExpected
Existing object200 and JSON with the right fields
Missing id404 and a JSON error
Broken JSON in a POST body400 and an error description
No auth401, not a web server page
User without rights403
Cyrillic in dataNot garbled, UTF-8

Common problems

  • 404 on the right address. The service is not published or published under another publication.
  • The response is an HTML page. The error happened before the handler: auth, publishing, licence.
  • Cyrillic is garbled. The body is not UTF-8 or charset is missing.
  • The client cannot parse JSON. A BOM at the start of the body, see unexpected character when reading JSON.

More on 1C

Section overview and all guides: 1C integration via API: options, architecture and examples.

Frequently asked questions

What address does a 1C HTTP service have?

http://server/publication/hs/root_url/template after publishing the database with HTTP services.

How do I return JSON?

Write the value with JSONWriter, create an HTTPServiceResponse with the code, add Content-Type: application/json; charset=utf-8 and set the body without a BOM.

How do I test it without coding?

Send requests with curl or an API client using a 1C account and check code, headers and body, including error cases.

Next step

Repeat this on your own API

Checkcraft is a desktop app that saves API response checks without code and shows what did not match. Start with a sample, then use your own sanitized data. Free runs on Windows and Linux with no time limit.

Download FreeDownload and first run

No sign-up or email needed, the archive is ready in a couple of minutes. See the edition limits.

References

RFC 9110: HTTP semantics

Start with the linked example and compare its result with your own test requirement.

Ask a person

Get help with your first test

Tell us what you want to test or where you got stuck. We can help you start Checkcraft, choose an example and understand your first run. You can ask before downloading.

The Telegram group is public: do not post passwords, tokens or confidential work data. A description of your task is enough to start.

You can also email us support@checkcraft.ru

No account required. We will reply by email. This is a support request, not a newsletter subscription.