API methods
- Manage
- Copy
- Actions
- Export
- Annotate
- Print Preview
- Viewers
- Source
- Children
- Annotations
- Attachments (3)
- History
Choose the export format from the list below:
- Office Formats (1)
-
Export as Portable Document Format (PDF) using Apache Formatting Objects Processor (FOP)
-
- Other Formats (1)
-
Export as HyperText Markup Language (HTML)
-
Questions related to the work of API methods:
Note: It is reccomended to read aboutthe technology stack used by the Loymax system.
Objects used in the .Net framework are translated from a data structure to a sequence of bytes or a string. In this format it is convenient to transfer and store data.
The process of translating an object state into a stream of bytes in order to store them in PC memory, a database or a file is called serialization. The main purpose of serialization is to save the state of an object so that it is possible to restore it if necessary.
The reverse translation of bytes into a data structure is called deserialization.The Loymax system uses the Newtonsoft.Json.JsonSerializer for serialization/deserialization.
Let's take the serialization/deserialization process as an example of how the method works for receiving a list of brands
All brands in the System are created using the same template (model), that is, they are inherited from the same data type.
The algorithm for obtaining information about brands through API methods works as follows:
- The client sends a request for a list of brands (GET: /v1.2/brands#).
- The server processes the request, generates and sends an SQL-query to the database to get a list of brands.
- The database, in response to a server request, returns to the server a list of brands that are translated from the byte stream back into a .Net object.
- The server returns to the client a list of brands in JSON format. The Newtonsoft.Json.JsonSerializer converts the .Net object into JSON format.
For example, in .NET there are types Brand1 and BrandBase (Brand1 inherits from BrandBase).
public class BrandBase
{
public string Name { get; set; }
public string Description { get; set; }
}
public class Brand1 : BrandBase
{
public string Code { get; set; }
}Newtonsoft JsonConvert adds $type property to JSON schema for types during serialization and uses it during deserialization.
Thus, serializing an instance of the Brand1 class will create a JSON object with the aforementioned $type property.
Brand1 is an object created using the BrandBase type. Since the serializer expects to get only an object of type BrandBase, and Brand1 recognizes it as a separate type that inherits from the common type BrandBase, it assigns it the $type property, which specifies the model that the object was created with, to create an object of the source type during deserialization.
In the response to the query for a list of brands, the information about Brand1 will look like this
{
"$type": "Loymax.Api.Models.BrandInfo.Brand1, Loymax.Api",
"name": "Brand1",
"description": "New Brand",
"code": "7878b563333841d79a5e5d14fde29cbe"
}
Last edited 06/03/2024 10:37