Why do we need GET blocks, and how do they work?

When you develop a frontend, you will inevitably need to run different BPs on the backend. In order to run a BP, you need to call its endpoint. To do this, AppMaster creates a Server Request block for each endpoint. These blocks have the same input and output fields as the associated endpoint and serve as a way to start it.

GET blocks, according to the principles of the REST API, must retrieve some data. Most often, GET blocks retrieve data from the model in the database (all, or by certain criteria).

Like all Server Request blocks, each GET block is bound to its own endpoint. The endpoint's Url is displayed in the name of the blocks.

Keep in mind that AppMaster generates basic endpoints automatically. But you can also create your BPs and endpoints for them, and consequently your Server Request blocks.

Input and output fields of the GET block

Input

  • Endpoint ID – determines which endpoint the block should access. This field is set automatically;
  • _offset – allows specifying from which record the block will receive information; integer format;
  • _limit – the number of records the block loads. The default is 25, the maximum at a time is 500; integer format;
  • _sort_order – two values ​​are suitable for this field: asc – direct sort order and desc – reverse order; string format;
  • _sort_by – defines by which field of the data model the list will be sorted; string format;
  • Ids – list of record ids. Allows to get records by specific id; array integer format;
  • _search – search for a given value in the data model; string format;
  • _search_exact – enables/disables exact match search; boolean format;
  • _ search_in – search by specific fields; array string format.

Let's take a closer look at the fields associated with the search.

_search – searches for matches throughout the data model and will find them regardless of the field in which the value is located.

For example, let's set the _search field to John. If in the data model, for one record, the value of the name field is John, and for the other, the value of the email field is [email protected], then the search will find both of these records.

_search_exact – enabling this field means that the results will include records that completely match the query.

Request

_search_exact

Result

John

False

John, Johny, [email protected]

John

True

John

_search_in – here, you can set the fields where the search should be carried out. For example, if we want to search only by names and not consider cases when the name is the part of the email, we can use _search_in and search only by the name field.

Search data model fields

These fields are used to search by the data model. The main difference between them and search fields is that they can take different values, unlike search, which only accepts string format.

Output

  • _success – search results; boolean format;
  • _httpcode – request response code; integer format;
  • _error – error text; string format;
  • Data – records received; array model format;
  • Count – the number of entries received; integer format.

The _with field

It appears in those blocks where the request goes to related data models. It allows you to get data from the data model to which the request is made and from the data models associated with it.

Let's look at the _with field using an example application that stores a list of books and their categories.

Create two data models: book and category. In the book we add the book_name field, and in the category we add the category_name field.

Create a connection between them. Let's draw it from category to book and set the type of relation to has_many since one category can refer to different books.

Under the web application tab, set up data loading into the book and category tables and add records to these tables. Linked data is not currently displayed in tables. To fix this, the _with field is needed.

Set up this field in the Get block for each table.

Now let's open our application and make sure that the query is running and that the right data appears in the table.

Was this article helpful?

AppMaster.io 101 Crash Course

10 modules
2 weeks

Not sure where to start? Get going with our crash course for beginners and explore AppMaster from A to Z.

Start Course
Development it’s so easy with AppMaster!

Need More Help?

Solve any issue with the help of our experts. Save time and focus on building your applications.

headphones

Contact Support

Tell us about your problem, and we’ll find you a solution.

message

Community Chat

Discuss questions with other users in our chat.

Join Community