Service
Service table is a system table, if you want to know more about it, please check the System Tables documentation.
Overview
- With services you can get data from the project tables using multiple queries from Query table.
- Services allow passing values to queries to get data dynamically.
- You can modify the results of the queries if needed via custom python code.
- Service results can be consulted using custom URLs.
Columns
Queries
In this column all queries created via the Query table will be listed in the format <ID> <QUERY_NAME>, you can choose one, multiple or none.
Custom Python Pre
Mainly you can use this field to pass values to queries that require parameters, this field has a dedicated environment see Reserved keywords in custom python fields section.
Custom Python Post
Mainly allows you to modify queries results, this field has a dedicated environment see Reserved keywords in custom python fields section.
Path
This value will be the one used to build the service custom URL.
Features
-
Maker mike will generate the URL for your service with the following structure
https://<DOMAIN>/makermike/api/<SERVICE_PATH>Where:
- The
<DOMAIN>can be your own domain or your project name as a subdomain of console.makermike.io16.com. - The
<SERVICE_PATH>segment is the value that you set in this field, once you have created your service MakerMike automatically builds the URL to consume your service, you can click the value in thepathcolumn to see your service result and the builded URL.
- The
-
Path allows the following special characters:
- $
- -
- _
- +
- !
- *
- '
- (
- )
- /
- <
- >
-
Prettify service result feature: This feature is only for you to visualize the result of your service but in a pretty format, once you click the value from the path column you can add in the browser URL in the query string section the key and value
pretty=True.Example
https://<DOMAIN>/makermike/api/<SERVICE_PATH>?pretty=True
Reserved keywords in custom python fields
The custom python fields have access to the following variables and python packages
markdown
The markdown.markdown function from the Python markdown library, made available by makermike-core, can be used to convert Markdown text into HTML.
Usage:
html = markdown.markdown(<YOUR_TEXT>, extensions=['tables', 'toc', 'attr_list', 'md_in_html'])
All extensions from the library are available. For a complete list, see the official Python-Markdown Extensions documentation.
Execute Query
MakerMike function that lets you write and execute queries, the syntax rules are the same as in the Query table.
Usage:
<VARIABLE_TO_STORE_RESULT> = execute_query("<YOUR_QUERY>")
The result returned by execute_query has the following format:
<VARIABLE_TO_STORE_RESULT>[ROW_INDEX][COLUMN_NAME]
json
Python encoder/decoder see more about here in the official Python json documentation.
path_parameters
Object/dictionary which contains all the path parameters names and values as key and value pairs.
You can use it for debug purposes, you can print any variable as long as it is string type and you can see the output when visualizing the service result.
query_rows
Object/dictionary that contains all the data of the selected queries from Query table, it has the following format:
query_rows[<SELECTED_QUERY_INDEX>][<COLUMN_NAME>]
Where:
<SELECTED_QUERY_INDEX>refers to the index of the query in thequeriescolumn list<COLUMN_NAME>refers to any column name of the Query table.
query_parameters
Object/dictionary, used to pass parameters to queries, each key must correspond to a selected query id, the value should be the parameters of the query inside a list.
Usage in custom python pre:
query_parameters = {
"<ID>": [<PARAMETER>, ...]
}
ID as integer
query_parameters = {
<ID>: [<PARAMETER>, ...]
}
Where:
<ID>Corresponds to the query id in Query table, you can see it in the lists of queries in thequeriesfield too.<PARAMETER>Should always be astringtype value, otherwise it can cause an error output when executing the service.
You can pass multiple parameters in the list, they have to be separated by comma. In the custom python post field the variable is available only for read purposes.
response
Object that can be used to create your own responses with headers and cookies.
To create a response use the function:
response.set_response(args)
args:
response: Optional argument, it is the content that you want to return and must be a string, if no value is established the response will be the service result.headers: You can set multiple headers in a key/value pair where the key is the header name and the value is the header value.cookies: You can set multiple cookies in the following format:cookies=[{name: "<COOKIE_NAME>", value: "<COOKIE_VALUE>", expires="<SECONDS>", path="<COOKIE_PATH>", domain="<COOKIE_DOMAIN>"}, ...]
Other methods
get_cookies(): Returns all cookies if no cookies were set the value returned will be an empty list.get_headers(): Return all the headers set, if no headers were set the value returned will be an empty dictionaryget_response(): Returns the value established for theresponseargument.get_code(): Returns the value established for theresponseargument.-
set_cookie(args): You can set a cookie. args:- name: The name of the cookie.
- value: the value of the cookie, the default value is an empty string.
- expires: expiration time in seconds.
- path: The path of the cookie, the cookie will only work in the designed path.
- domain: The domain of the cookie, the cookie will only be available in this domain.
-
set_header(args): You can set a cookie. args:- name: The name of the header.
- value: the value of the header.
redirect
Object that can be used to make a redirection to another page.
To create the redirection use the following function:
redirect.set_response(args)
redirect has the same methods and parameters as response has, for redirect the response value must be the path to the page that you want to redirect.
request
Object/dictionary from Flask, to access incoming request data, you can check more about it at Flask request object.
user_data_in_current_project
Object/dictionary which contains all the data present in the User table of the current user, each key corresponds to a column name of the table, only for read purposes.
Python builtins
python builtins with the exception of the following functions [breakpoint, credits, compile, copyright, eval, exec, exit, help, input, memoryview, open, print, property, license, quit]
Reserved keywords only in custom python post
queries_results
This variable is a list of lists, each nested list corresponds to a row in dictionary format, each key of the dictionary corresponds to a column name, the column names will depend on the result of the query.
Variable format example:
queries_results[<QUERY_INDEX>][<ROW_ID>][<COLUMN_NAME>]
Service availability
Make sure that you have set the proper roles in the read permissions of:
- The column
pathin theServicetable. - All columns of the Query table.
- For the tables used by the selected queries in the
queriescolumn, depending on what columns and tables the queries use, the queries executed by the functionexecute_querywill need the same permissions.