{"id":19475722,"url":"https://github.com/iondv/rest","last_synced_at":"2025-02-25T15:47:58.169Z","repository":{"id":56152209,"uuid":"181287165","full_name":"iondv/rest","owner":"iondv","description":"REST is an IONDV. Framework module for system integration.","archived":false,"fork":false,"pushed_at":"2021-03-08T06:12:46.000Z","size":79,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-01-08T06:33:17.796Z","etag":null,"topics":["integration","iondv","iondv-module","javascript","rest","restful-api"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/iondv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-14T09:35:12.000Z","updated_at":"2019-11-01T08:33:49.000Z","dependencies_parsed_at":"2022-08-15T13:40:40.647Z","dependency_job_id":null,"html_url":"https://github.com/iondv/rest","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iondv%2Frest","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iondv%2Frest/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iondv%2Frest/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/iondv%2Frest/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/iondv","download_url":"https://codeload.github.com/iondv/rest/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240699552,"owners_count":19843512,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["integration","iondv","iondv-module","javascript","rest","restful-api"],"created_at":"2024-11-10T19:34:24.047Z","updated_at":"2025-02-25T15:47:58.109Z","avatar_url":"https://github.com/iondv.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"This page in [Русском](/README_RU.md)\n\n# IONDV. REST\n\nREST - is an **IONDV. Framework** module used to quickly create web services\nbased on metadata for implementing microservice architecture. The module also allows you to\nintegrate applications created on the framework with other systems using the REST API and it\nprovides data exchange to implement arbitrary custom web interfaces\n(including [SPA](https://en.wikipedia.org/wiki/Single-page_application) created on the frameworks [Angular](https://angularjs.org), [Redux](https://redux.js.org), [Vue](https://ru.vuejs.org), etc.).\n\n### IONDV. Framework in brief\n\n**IONDV. Framework** - is a node.js open source framework for developing accounting applications\nor microservices based on metadata and individual modules. Framework is a part of \ninstrumental digital platform to create enterprise \n(ERP) apps. This platform consists of the following open-source components: the [IONDV. Framework](https://github.com/iondv/framework), the\n[modules](https://github.com/topics/iondv-module) and ready-made applications expanding its\nfunctionality, visual development environment [Studio](https://github.com/iondv/studio) to create metadata for the app.\n\n* For more details, see [IONDV. Framework site](https://iondv.com). \n\n* Documentation is available in the [Github repository](https://github.com/iondv/framework/blob/master/docs/en/index.md).\n\n## Description\n\n**IONDV. REST** - is a module providing a way to work with the data of IONDV applications via `REST API`.\nIt's a wrapper to work with the data via standard CRUD functions, it also connects the\napplication's own services, including those using the core API.\n\n## Functionality\n\nOverview:\n\n* [Service registration in application configuration](#service-registration-in-application-configuration)\n* [Authorization for service requests](#authorization-for-service-requests)\n* [Built-in module services](#built-in-module-services)\n* [Service handler in the app](#service-handler-in-the-app)\n* [Additional services](#additional-services)\n\n### Service registration in application configuration \n\nTo connect services in the application, configure them in the global settings of the rest module in the deploy.json file of the application. For example:\n\n```json\n{\n  \"modules\": {\n    \"rest\": {\n      \"globals\": {\n        \"di\": {\n          \"simple\": {\n            \"module\": \"applications/develop-and-test/service/SimpleRest\"\n          },\n          \"string-list\": {\n            \"module\": \"applications/develop-and-test/service/String-list\",\n            \"options\": {\n              \"stringClassName\": \"class_string@develop-and-test\",\n              \"dataRepo\": \"ion://dataRepo\"\n            }\n          },\n          \"crud\": {\n            \"module\": \"modules/rest/lib/impl/crud\",\n            \"options\": {\n               \"auth\": \"ion://auth\",\n               \"dataRepo\": \"ion://securedDataRepo\"\n            }\n          }\n```\n\nThe path to the service registration is in the `deploy.json` file - `modules.rest.globals.di`, further specify the name of the service, which will be available at the following address `https://domain.com/rest/serviceName`, where `serviceName` - name of the service, set in the di, as in the example above `simple` or `string-list`. In the `module` attribute, specify the path to the js-file with a service handler with a relative path\nthe root of the framework. The handler can be both in the application and in any module or framework, including sample rest module handlers.\n\nIn the `options` property, the specific service parameters are set.\n\nFor example, for **crud** service:\n\n* `dataRepo` filed - data repository with access control used for operations on objects\n* `auth` field - authentication component used to obtain the current user account.\n\nFor **string-list** service:\n\nused for data sampling\n\n* `dataRepo` field - data repository, used for data sampling\n* `stringClassName` field - class name of received objects\n\nIn this case, the `class_string@develop-and-test` class will be transferred to the `getList` method of the data repository.\n\n```javascript\n\noptions.dataRepo.getList(options.stringClassName, {})\n\n```\n\n### Authentication for service queries\n\nThere are several ways to carry out the authorization:\n\n#### Standart authorization services via the login account  \n\nAll services use the standard authorization mechanism by default, which implies the transfer of \tregistration details in the header:\n\n* authorization via basicAuth, for example:\n\n```bash\ncurl -u demo@local:ion-demo https://dnt.iondv.com/rest/simple\n```\n\n* transfer of\tregistration details in the query header:\n```bash\ncurl -H \"auth-user: demo\" -H \"auth-pwd: ion-demo\" -H \"auth-user-type: local\" https://dnt.iondv.com/rest/simple\n```\n\nor\n\n```bash\ncurl -H \"auth-user: demo@local\" -H \"auth-pwd: ion-demo\" https://dnt.iondv.com/rest/simple\n```\n\n\n#### Services without the authentication\n\nTo implement the service without authentication, you must set the `none` parameter in the `deploy.json` file:\n\n```json\n{\n  \"modules\": {\n    \"rest\": {\n      \"globals\": {\n        \"authMode\": {\n          \"echo\": \"none\"\n```\n\nA query to a service will not require authentication, an example query - `curl https://dnt.iondv.com/rest/echoo`\n\n#### Services with token authentication\n\nToken authentication is used to exclude the constant transfer of an account in queries. Tokens are limited in their lifetime.\n\nTo implement the work of the service with authentication through a token, you must set the `token` parameter in the `authMode` in the `deploy.json` file:\n\n```json\n{\n  \"modules\": {\n    \"rest\": {\n      \"globals\": {\n        \"authMode\": {\n          \"echo-token\": \"token\"\n```\n\nAuthentication through the token is carried out by sending the token value for the `auth-token` parameter in the request header:\n\n```bash\ncurl -H \"auth-token: c369a361db9742e9a9ae8e9fe55950a571493812\" http://dnt.iondv.com/rest/echo-token\n```\n\nYou can get a token in two ways: in the console of the ionadmin module or through the `token` service of the rest module.\n\nAll generated tokens are stored in the collection `ion_user_tokens` in the database.\n\n##### Getting a constant token through the ionadmin module\n\nTo get a token through the admin console, go to the \"Web Services Security Keys\" navigation item of the ionadmin module, by going to `locahost:8888/ionadmin/token`.\n\nOn the \"Security Token Generator\" page:\n\n* Enter the user name in the \"User name\" field\n* Set the \"Account Type\" field to \"local\"\n* Click the \"Generate token\" button\n* In the \"Token\" field the token value as follows `3a546090355317c287886c0e81dfd304fa5bda99` will appear. Use it as the `auth-token` header value.\n\nThe default token lifetime is 100 years.\n\n##### Getting a temporary token through the rest/token service\n\nThe second way to get the token is to use the web service of the rest module - `token`. You can get a token through\nauthenticated request to the `rest/token` address. For example, through the authorization basicAuth type:\n\n```bash\ncurl -u demo@local:ion-demo https://dnt.iondv.com/rest/token\n```\nor a request with authorization through the parameters in the header:\n\n```bash\ncurl -H \"auth-user: demo@local\" -H \"auth-pwd: ion-demo\" -H https://dnt.iondv.com/rest/token\n```\n\nThe service response will have a token of the form `e444c69894d2087696e0a6c6914788f67ebcf6ee`. The default token lifetime is 100 years.\n\nTo execute the request, you must either have administrator rights in the system or have `use` rights for the `ws:::gen-ws-token` resource.\n\nYou can add a token generation resource for a role from the command line `node bin/acl.js --role restGrp --p USE --res ws:::gen-ws-token` (where restGrp - name of existing group)\n \nThe second way to add rights to a resource is to use the admin console of the ionadmin module, for example, by going to `locahost:8888/ionadmin/`:\n\n* Select the \"Security\" navigation item,\n* Select the Roles navigation subitem,\n* Select an existing role and click the edit or create a new role buttons, \n* In the \"Access righrs\" field, select the Services item,\n* Expand the list of rights for the \"Generation of security tokens through web services (ws ::: gen-ws-token)\" resource,\n* Select \"Use\" and click \"Save\".\n\n### Built-in module services\n\nThe REST module has several built-in services designed to implement typical operations with the module:\n\n* `acceptor` - service provides mass creation of objects\n* `token` -  service provides the issuance of a token for an authorized user\n* `crud` - CRUD service for system objects\n\n#### Built-in \"acceptor\" service\n\nThe `acceptor` service designed for mass storage of objects of different classes.\n\nIt is required to register the service in the deploy.json application configuration file to work with the service. At the same time, the service must be indicated in the `options` - the `dataRepo` and `metaRepo` repositories. For example:\n\n```json\n{\n  \"modules\": { \n    \"rest\": {\n      \"globals\": {\n        \"di\": {\n          \"acceptor\": {\n            \"module\": \"modules/rest/lib/impl/acceptor\",\n            \"options\": {\n              \"dataRepo\": \"ion://dataRepo\",\n              \"metaRepo\": \"ion://metaRepo\"\n            }\n          }\n```\n\nAuthorization is carried out through all the main types of access, and by default through the user account.\n\nThe service is carried out by the `POST` method, objects are transferred as an array of objects in JSON format in the request body with the json content header `Content-Type:application/json`. Auto-generated fields are optional.\n\nIn the header in the `ion-converter` property, the name of the converter that can be used when processing data can be passed.\nBoth request data and response data. In this case, the data converter itself must be registered in the `options` service.\nIf no handler is specified, the default handler is used.\n\nThe object data must include:\n\n* `_id` - identifier of the object by key field\n* `_class` - object class with namespace\n* `_classVer` - class version\n\nThe remaining values must match the properties of the class, including data type matching. Example.\n\n```bash\ncurl -X POST -u demo@local:ion-demo \\\n   -H \"Content-Type:application/json\" \\\n   -d '[{\"_class\": \"class_string@develop-and-test\", \"__classVer\": null,\"id\": \"10101010-5583-11e6-aef7-cf50314f026b\",\\\n       \"string_text\": \"Example10\", \"string_miltilinetext\": \"Example10\", \"string_formattext\": \"Example10\"}]' \\\n   https://dnt.iondv.com/rest/acceptor\n```\n\nThe method returns the code `200` and an array of stored objects.\n\n```json\n[\n  {\n    \"id\": \"10101010-5583-11e6-aef7-cf50314f026b\",\n    \"_class\": \"class_string@develop-and-test\",\n    \"_classVer\": \"\",\n    \"string_formattext\": \"Example10\",\n    \"string_miltilinetext\": \"Example10\",\n    \"string_text\": \"Example10\",\n    \"_id\": \"10101010-5583-11e6-aef7-cf50314f026b\"\n  }\n]\n```\n\nIn case of an error, the response code will be `400`, and the response text will contain\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n\u003cmeta charset=\"utf-8\"\u003e\n\u003ctitle\u003eError\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n\u003cpre\u003eBad Request\u003c/pre\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n#### Built-in service \"token\"\n\nThe `token` service is intended for issuing a token to an authenticated user, for its further use in token authentication services.\n\nThe service does not require registration in deploy.json. The service provides the issuance of a token for an authorized user, \nif he has the `use` rights for the `ws:::gen-ws-token` resource or has administrator rights. In response to the request, there is a token of the following type `e444c69894d2087696e0a6c6914788f67ebcf6ee`. The default token lifetime is 100 years.\n\nRequest example via authentication of the basicAuth type:\n\n```bash\ncurl -u demo@local:ion-demo https://dnt.iondv.com/rest/token\n```\n \nExample request with authentication through parameters in the header\n\n```bash\ncurl -H \"auth-user: demo@local\" -H \"auth-pwd: ion-demo\" -H \"auth-user-type: local\" https://dnt.iondv.com/rest/token\n```\n\n#### Built-in service \"crud\"\n\nThe `crud` service implements a REST API based on the basic CRUD operations (create, read, update, delete).\n\nThe service requires registration in deploy.json of the application and requires a mandatory data source `dataRepo` in `options` of the service, as well as the authorization source `auth` to access user data.\nIt is advisable to specify as a data repository - a repository with full security processing in order to test the access to objects taking into account dynamic security. For example:\n\n```json\n{\n  \"modules\": { \n    \"rest\": {\n      \"globals\": {\n        \"di\": {\n          \"crud\": {\n            \"module\": \"modules/rest/lib/impl/crud\",\n            \"options\": {\n              \"auth\": \"ion://auth\",\n              \"dataRepo\": \"ion://securedDataRepo\"\n            }\n          }\n```\n\nAuthentication is done through all the main types of access, and by default through a user account.\n\nExample:\n\n```bash\ncurl -X POST -u demo@local:ion-demo https://dnt.iondv.com/rest/crud\n```\n\nBy default, without the correct parameters - server response code about the error is `404`. \n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n\u003cmeta charset=\"utf-8\"\u003e\n\u003ctitle\u003eError\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n\u003cpre\u003eCannot POST /rest/crud\u003c/pre\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n##### Getting a list of objects: GET crud/:class@namespace method\n\nGetting a list of objects is carried out by the `GET` method, while indicating the class code with a namespace, for example `rest/crud/class_string@develop-and-test/`\n\n```bash\ncurl -X GET -u demo@local:ion-demo https://dnt.iondv.com/rest/crud/class_string@develop-and-test/\n```\nIn response, the service returns a JSON Object with an offset of 0 and a count of 5 records and a status of `200`, if there is no such class, returns the code `404`.\n\n```json\n[{\"_creator\":\"admin@local\",\n\"_id\":\"4567a830-b8ea-11e9-9cdf-7bd384cbb7a5\",\n\"__string\":\"example1\",\n\"__class\":\"class_string@develop-and-test\",\n\"__classTitle\":\"Class \\\"String [0]\\\"\",\n\"id\":\"4567a830-b8ea-11e9-9cdf-7bd384cbb7a5\",\n\"string_text\":\"example1\",\n\"string_miltilinetext\":\"example1\",\n\"string_formattext\":\"\u003cp\u003eexample1\u003c/p\u003e\"},\n{\"_id\":\"66dbb3d0-5583-11e6-aef7-cf50314f026b\",\n\"__string\":\"Example of the \\\"String [0]\\\" type in the \\\"Text [1]\\\" view\",\n\"__class\":\"class_string@develop-and-test\",\n\"__classTitle\":\"Class \\\"String [0]\\\"\",\n\"id\":\"66dbb3d0-5583-11e6-aef7-cf50314f026b\",\n\"string_text\":\"Example of the \\\"String [0]\\\" type in the \\\"Text [1]\\\" view\",\n\"string_miltilinetext\":\"Example of the \\\"String [0]\\\"\\r\\n in the Multiline text [7] view\",\n\"string_formattext\":\"Example of the \\r\\n \\\"String [0]\\\" type \\r\\n in the \\r\\nFormatted text [7] view\"}]\n```\n\nThe query can be implemented with the following query parameters:\n\n* `_offset` - sample offset, 0 - by default\n* `_count` - number of values in the sample, 5 - by default\n* `_eager` - a list of class properties, separated by the symbol `|` for which it is necessary to configure the data eager loading.\n* `[name of property]` - all parameters are accepted by the request name, except those starting with `_` which are considered the names of the class attributes, and their values are set as filters.\n\nExamples:\n\n```bash\n# Запрос списка объектов класса со смещением 1 и кол-вом 2\ncurl -X GET -u demo@local:ion-demo https://dnt.iondv.com/rest/crud/class_string@develop-and-test/?_offset=1\u0026_count=2\n# Запрос списка объектов, у которы свойство string_text имеет значение example1\ncurl -X GET -u demo@local:ion-demo https://dnt.iondv.com/rest/crud/class_string@develop-and-test/?string_text=example1\n# Запрос списка объектов, у которы свойство string_text имеет значение example1, со смещением 1 и кол-вом 2\ncurl -X GET -u demo@local:ion-demo https://dnt.iondv.com/rest/crud/class_string@develop-and-test/?string_text=example1\u0026_offset=1\u0026_count=2\n```\n\n##### Check of the object availability: HEAD crud/:class@namespace/:id method\n\nCheck of the object availability is carried out by the `GET` method, while indicating the class code with a namespace and the value of the object key, for example `rest/crud/class_string@develop-and-test/66dbb3d0-5583-11e6-aef7-cf50314f026b`\n\n```bash\ncurl -X HEAD -u demo@local:ion-demo https://dnt.iondv.com/rest/crud/class_string@develop-and-test/66dbb3d0-5583-11e6-aef7-cf50314f026b\n```\n\nIf the object exists, it returns the response code `200`, if the object does not find the code is `404`, if there is no correct rights - `403`.\n\n##### Receiving object: GET crud/:class@namespace/:id method\n\nObtaining an object is carried out by the `GET` method, while indicating the class code with a namespace and the value of the object key, for example `rest/crud/class_string@develop-and-test/66dbb3d0-5583-11e6-aef7-cf50314f026b`\n\n```bash\ncurl -X GET -u demo@local:ion-demo https://dnt.iondv.com/rest/crud/class_string@develop-and-test/66dbb3d0-5583-11e6-aef7-cf50314f026b\n```\n\nIn addition, you can set the `_eager` parameter in the query containing a list of class properties, separated by the `|` symbol\nfor which it is necessary to configure the data eager loading (links or collections). For example:\n\n```bash\ncurl -X GET -u demo@local:ion-demo https://dnt.iondv.com/rest/crud/class_string@develop-and-test/66dbb3d0-5583-11e6-aef7-cf50314f026b?_eager=string_text\n```\n\nIf the object exists, it returns the response code `200` and the object itself in json format, if the object does not find the code is `404`, if there is no correct rights - `403`.\n\n```json\n{\n    \"_id\": \"66dbb3d0-5583-11e6-aef7-cf50314f026b\",\n    \"__string\": \"Example of the \\\"String [0]\\\" type in the \\\"Text [1]\\\" view\",\n    \"__class\": \"class_string@develop-and-test\",\n    \"__classTitle\": \"Class \\\"String [0]\\\"\",\n    \"id\": \"66dbb3d0-5583-11e6-aef7-cf50314f026b\",\n    \"string_text\": \"Example of the \\\"String [0]\\\" type in the \\\"Text [1]\\\" view\",\n    \"string_miltilinetext\": \"Example of the \\\"String [0]\\\"\\r\\n in the Multiline text [7] view\",\n    \"string_formattext\": \"Example of the \\r\\n \\\"String [0]\\\" type \\r\\n in the \\r\\nFormatted text [7] view\"\n}\n```\n\n##### Object creation: POST crud/:class@namespace method\n\nAn object is created using the `POST` method, and the class code with a namespace is specified, `rest/crud/class_string@develop-and-test`. The object itself is transmitted in the request body in json format with obligatory indication in the header of the json content type `Content-Type:application/json`. Auto-generated fields are optional. Example:\n\n```bash\ncurl -X POST -u demo@local:ion-demo \\\n   -H \"Content-Type:application/json\" \\\n   -d '{\"string_text\": \"Example3\", \"string_miltilinetext\": \"Example3\", \"string_formattext\": \"Example3\"}' \\\n   https://dnt.iondv.com/rest/crud/class_string@develop-and-test/\n```\n\nThe created object will be returned in response, in which all auto-created fields will be filled and the response code will be  `200`.\n\n```json\n{\n    \"_creator\": \"admin@local\",\n    \"_id\": \"10c77900-b96e-11e9-a7ce-314f02bd4197\",\n    \"__string\": \"10c77900-b96e-11e9-a7ce-314f02bd4197\",\n    \"__class\": \"class_string@develop-and-test\",\n    \"__classTitle\": \"Class \\\"String [0]\\\"\",\n    \"id\": \"10c77900-b96e-11e9-a7ce-314f02bd4197\",\n    \"string_text\": \"Example3\",\n    \"string_miltilinetext\": \"Example3\",\n    \"string_formattext\": \"Example3\"\n}\n```\n\nIn case of an error, the response code will be `400`, and the response text will contain:\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n\u003cmeta charset=\"utf-8\"\u003e\n\u003ctitle\u003eError\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n\u003cpre\u003eBad Request\u003c/pre\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n##### Object update: PATCH or PUT crud/:class@namespace/:id method\n\nUpdating an object is done using the `PATCH` or` PUT` method, and the class code with neispace and the value of the object key are indicated, for example `rest/crud/class_string@develop-and-test/66dbb3d0-5583-11e6-aef7-cf50314f026b`. The object itself is transmitted in the request body in json format with obligatory indication in the header of the json content type - `Content-Type:application/json`. \n\nExample:\n\n```bash\ncurl -X PATCH -u demo@local:demo-ion -H \"Content-Type:application/json\" -d '{\"string_text\": \"NEW Example\", \"string_miltilinetext\": \"NEW Example\", \"string_formattext\": \"NEW Example\"}' https://dnt.iondv.com/rest/crud/class_string@develop-and-test/66dbb3d0-5583-11e6-aef7-cf50314f026b\n# Or it is equivalent\ncurl -X PUT -u demo@local:demo-ion -H \"Content-Type:application/json\" -d '{\"string_text\": \"NEW Example\", \"string_miltilinetext\": \"NEW Example\", \"string_formattext\": \"NEW Example\"}' https://dnt.iondv.com/rest/crud/class_string@develop-and-test/66dbb3d0-5583-11e6-aef7-cf50314f026b\n```\n\n\nIf the object exists, it returns the response code `200` and the object itself in json format, if the object does not find the code is `404`, if the processing fails, the code is `500`, if there is no correct rights - `403`.\n\nObject example:\n\n```json\n{\n    \"_editor\": \"admin@local\",\n    \"_id\": \"66dbb3d0-5583-11e6-aef7-cf50314f026b\",\n    \"__string\": \"NEW Example\",\n    \"__class\": \"class_string@develop-and-test\",\n    \"__classTitle\": \"Class \\\"String [0]\\\"\",\n    \"id\": \"66dbb3d0-5583-11e6-aef7-cf50314f026b\",\n    \"string_text\": \"NEW Example\",\n    \"string_miltilinetext\": \"NEW Example\",\n    \"string_formattext\": \"NEW Example\"\n}\n```\n\n##### Delete object: DELETE crud/:class@namespace/:id method\n\nDeleting an object is carried out by the `DELETE` method, while indicating the class code with a namespace and the value of the object key, \nfor example `rest/crud/class_string@develop-and-test/66dbb3d0-5583-11e6-aef7-cf50314f026b`.\n\n```bash\ncurl -X DELETE -u demo@local:demo-ion https://dnt.iondv.com/rest/crud/class_string@develop-and-test/66dbb3d0-5583-11e6-aef7-cf50314f026b\n```\n\nIf successful, the service returns the response code `200`, in case the object was not found `404`.\n\n\n### Service сreation\n\nCreating your own service consists of the following:\n\n* service registration in deploy.json\n* creating a service handler in the application\n* implementation of request processing logic\n\n#### Service registration in deploy.json application\n\nTest service registration example, for details see [Service registration in application configuration](#регистрация-сервиса-в-конфигурации-приложения)\n\n```json\n{\n  \"modules\": { \n    \"rest\": {\n      \"globals\": {\n        \"di\": {\n          \"string-list\": {\n            \"module\": \"applications/develop-and-test/service/String-list\",\n            \"options\": {\n              \"stringClassName\": \"class_string@develop-and-test\",\n              \"dataRepo\": \"ion://dataRepo\"\n            }\n          }        \n```\n\n#### Development of the service handler in the app\n\nAll services are implemented as heirs from Service - functions of the rest module.\n\nEach service must export a handler function in which an asynchronous method `this._route` are implemented. It is necessary to register processed methods and paths, throuth the `this.addHandler` functions, returning the Promise . Handler function\nwill have access to `options` and the access to the data repositories, authorization, metadata and classes (if they are specified in the application configuration in the deploy.json file) and will also receive an object with the generic name `req` - which is the `request` object of the [express](https://expressjs.com/en/4x/api.html#req) library.\n\nThe data, already parsed into the object will be located in `req.body`.\n \nThe handler function must return a Promise resolving to the result of the handler (for processing in Service `modules/rest/lib/interfaces/Service.js`), the handler will issue it with a code of 200 and a content type - `Content-Type:application/json`. \nIf during processing there will be an error intercepted by catch, then for errors related to access control, an answer with an error text and code will be returned `403`, and for everything else, the response code `500` and error message `Internal server error`. \n \nAn example of implementing a service issuing lists of objects with filters for a `class_string` class in the [develop-and-test] application.\n\nIt is also convenient to study the crud method itself, located at `modules/rest/lib/impl/crud.js`\n\n```javascript\nconst Service = require('modules/rest/lib/interfaces/Service');\n\n/**\n * @param {{dataRepo: DataRepository, echoClassName: String}} options\n * @constructor\n */\nfunction listClassString(options) {\n\n  /**\n   * @param {Request} req\n   * @returns {Promise}\n   * @private\n   */\n  this._route = function(router) {\n    this.addHandler(router, '/', 'POST', (req) =\u003e {\n      return new Promise(function (resolve, reject) {\n        try {\n          let filter = [];\n          if (req.body.string_text)\n            filter.push({string_text: {$eq: req.body.string_text}});\n          if (req.body.string_miltilinetext)\n            filter.push({string_miltilinetext: {$eq: req.body.string_miltilinetext}});\n          if (filter.length === 0)\n            filter = {};\n          else if (filter.length === 1)\n            filter = filter[0];\n           else\n            filter = {$and: filter};\n          options.dataRepo.getList(options.stringClassName, {filter: filter}).then(function (results) {\n            let items = [];\n            for (let i = 0; i \u003c results.length; i++) {\n              const props = results[i].getProperties();\n              const item = {};\n              for (let p in props) {\n                if (props.hasOwnProperty(p))\n                  item[props[p].getName()] = props[p].getValue();\n              }\n              items.push(item);\n            }\n            resolve({data: items});\n          });\n        } catch (err) {\n          reject(err);\n        }\n      });\n    });\n  }\n}\n\nlistClassString.prototype = new Service();\n\nmodule.exports = listClassString;\n```\n\nQuery without attributes in the query body:\n\n```bash\ncurl -X POST -u demo@local:ion-demo https://dnt.iondv.com:8888/rest/string-list\n```\n\nReturns all the list:\n\n```json\n[{\"__class\":\"class_string@develop-and-test\",\n  \"__classTitle\":\"Class \\\"String [0]\\\"\",\n  \"id\":\"4567a830-b8ea-11e9-9cdf-7bd384cbb7a5\",\n  \"string_text\":\"example1\",\n  \"string_miltilinetext\":\"example1\",\n  \"string_formattext\":\"\u003cp\u003eexample1\u003c/p\u003e\"},\n{\"__class\":\"class_string@develop-and-test\",\n  \"__classTitle\":\"Class \\\"String [0]\\\"\",\n  \"id\":\"4a80bdc0-b8ea-11e9-9cdf-7bd384cbb7a5\",\n  \"string_text\":\"example1\",\n  \"string_miltilinetext\":\"example2\",\n  \"string_formattext\":\"\u003cp\u003eexample2\u003c/p\u003e\"},\n{\"__class\":\"class_string@develop-and-test\",\n  \"__classTitle\":\"Class \\\"String [0]\\\"\",\n  \"id\":\"66dbb3d0-5583-11e6-aef7-cf50314f026b\",\n  \"string_text\":\"Example of the \\\"String [0]\\\" type in the \\\"Text [1]\\\" view\",\n  \"string_miltilinetext\":\"Example of the \\\"String [0]\\\"\\r\\n in the Multiline text [7] view\",\n  \"string_formattext\":\"Example of the \\r\\n \\\"String [0]\\\" type \\r\\n in the \\r\\nFormatted text [7] view\"}]\n```\n\nA query with an attribute parameter equal to the value in the attribute string_text:\n\n`Example of the \\\"String [0]\\\" type in the \\\"Text [1]\\\" view`\n\n```bash\ncurl -X POST -d \"string_text=Example of the \\\"String [0]\\\" type in the \\\"Text [1]\\\"\" \\\n     -u demo@local:ion-demo https://dnt.iondv.com:8888/rest/string-list\n```\n\nReturns the objects objects satisfying the condition:\n\n```json\n[{\"__class\":\"class_string@develop-and-test\",\n  \"__classTitle\":\"Class \\\"String [0]\\\"\",\n  \"id\":\"66dbb3d0-5583-11e6-aef7-cf50314f026b\",\n  \"string_text\":\"Example of the \\\"String [0]\\\" type in the \\\"Text [1]\\\" view\",\n  \"string_miltilinetext\":\"Example of the \\\"String [0]\\\"\\r\\n in the Multiline text [7] view\",\n  \"string_formattext\":\"Example of the \\r\\n \\\"String [0]\\\" type \\r\\n in the \\r\\nFormatted text [7] view\"}]\n```\n### Additional services\n\n* [The SEARCH method](/docs/en/method_search.md)\n* [Sending requests with files in the CRUD service](/docs/en/methods_crud.md)\n* [Work-flow execution service](/docs/en/performance_workflow.md)\n* [Metadata publishing service](/docs/en/service_metadata.md)\n--------------------------------------------------------------------------  \n\n #### [Licence](/LICENSE) \u0026ensp;  [Contact us](https://iondv.com) \u0026ensp;  [Russian](/README_RU.md)         \n\n--------------------------------------------------------------------------  \n\nCopyright (c) 2018 **LLC \"ION DV\"**.  \nAll rights reserved. ","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiondv%2Frest","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fiondv%2Frest","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fiondv%2Frest/lists"}