Creating a custom function endpoint
Kuroco allows you to create endpoints for custom functions.
Advantages of custom functions
With custom functions, you can freely add processes that may be difficult to implement using only the standard API endpoint functions. This in turn enables you to respond flexibly to a variety of use cases like the following:
- Update request/response content
- Hook a function to an API
- Implement your own security measures
This tutorial explains how to link your endpoints to custom functions.
GET
endpoint and custom function
First, we will create a sample GET
endpoint, and then link it with a custom function named PlainCustomFunction
.
Create your GET
endpoint
On your endpoint list screen, click [Add new endpoint].
Configure the settings dialog as follows:
Field(s) | Sub-field | Input |
---|---|---|
Path | - | plain-custom-endpoint |
Enabled/Disabled | Enabled | |
Model | Category | API |
Model | API | |
Operation | request_api | |
Summary (optional) | - | PlainCustomFunction Note: Enter a clear name for your endpoint here. We recommend using the name of your custom function. |
Description (optional) | - | GET endpoint for PlainCustomFunction. Note: Enter a clear description for your endpoint here. We recommend briefly explaining the purpose of your function. |
Basic settings | name | PlainCustomFunction Note: Enter the slug of your custom function here. |
When you are done, click [Add] to save the settings.
Create your custom function
Next, navigate to the Custom function list screen, and click [Add] in the upper right corner.
Configure the Custom function editor as follows:
| Field(s) | Input |
| :--- | :--- |
| Title | PlainCustomFunction
|
| Category | Uncategorized |
| Identifier | PlainCustomFunction
|
| Process |
- Theme: Visual Studio
- Language: Kuroco Smarty
{* Return a simple dummy string. *}
{capture name=data}
{literal}
response text
{/literal}
{/capture}
{assign var=data value=$smarty.capture.data}
When you are done, click [Add] to save the settings.
Verify the GET
endpoint activity
Now, verify the behavior of your GET
endpoint from the Swagger UI screen.
On the endpoint list screen, click [Swagger UI].
Select plain-custom-endpoint
, which you created earlier.
Click [Try it out].
Then, click [Execute].
You should see the contents of the function displayed under "Response body".
POST
endpoint and custom function
Now we will create a sample POST
endpoint and link it with the custom function PlainCustomFunctionPost
.
Create your POST
endpoint
Create your POST
endpoint
On your endpoint list screen, click [Add new endpoint].
Configure the settings dialog as follows:
Field(s) | Sub-field | Input |
---|---|---|
Path | - | plain-custom-endpoint-post |
Enabled/Disabled | Enabled | |
Model | Category | API |
Model | API | |
Operation | request_api_post | |
Summary (optional) | - | PlainCustomFunctionPost Note: Enter a clear name for your endpoint here. We recommend using the name of your custom function. |
Description (optional) | - | POST endpoint for PlainCustomFunctionPost. Note: Enter a clear description for your endpoint here. We recommend briefly explaining the purpose of your function. |
Basic settings | name | PlainCustomFunctionPost Note: Enter the slug of your custom function here. |
When you are done, click [Add] to save the settings.
Create your custom function
Next, navigate to the function list screen and click [Add] in the upper right corner.
Configure the function editor as follows:
Field(s) | Input |
---|---|
Title | PlainCustomFunctionPost |
Category | Uncategorized |
Slug | PlainCustomFunctionPost |
Process |
|
Status | Publish |
{* Return a simple dummy string. *}
{capture name=data}
{literal}
response text
{/literal}
{/capture}
{assign var=data value=$smarty.capture.data}
Verify the POST
endpoint activity
Now, verify the behavior of your POST
endpoint from the Swagger UI screen.
On the endpoint list screen, click [Swagger UI].
Select plain-custom-endpoint-post
, which you created earlier.
Click [Try it out].
Then, click [Execute].
You should see the contents of the function displayed under "Response body".
Implementation of custom functions
This concludes the procedures for linking custom functions to API endpoints. For more information about the implementation such functions, refer to the tutorials below:
Support
If you have any other questions, please contact us or check out Our Slack Community.