Skip to main content

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].

Image from Gyazo

Configure the settings dialog as follows:

Image from Gyazo

Field(s)Sub-fieldInput
Path-plain-custom-endpoint
Enabled/DisabledEnabled
ModelCategoryAPI
ModelAPI
Operationrequest_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 settingsnamePlainCustomFunction
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.

Image from Gyazo

Configure the Custom function editor as follows:

Image from Gyazo

   | Field(s) | Input | | :--- | :--- | | Title | PlainCustomFunction | | Category | Uncategorized | | Identifier | PlainCustomFunction | | Process |

  • Theme: Visual Studio
  • Language: Kuroco Smarty
*Paste the source code below into the text area. | | Status | Publish |

{* 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].

Image from Gyazo

Select plain-custom-endpoint, which you created earlier.

Image from Gyazo

Click [Try it out].

Image from Gyazo

Then, click [Execute].

Image from Gyazo

You should see the contents of the function displayed under "Response body".

Image from Gyazo

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].

Image from Gyazo

Configure the settings dialog as follows:

Image from Gyazo

Field(s)Sub-fieldInput
Path-plain-custom-endpoint-post
Enabled/DisabledEnabled
ModelCategoryAPI
ModelAPI
Operationrequest_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 settingsnamePlainCustomFunctionPost
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.

Image from Gyazo

Configure the function editor as follows:

Image from Gyazo

Field(s)Input
TitlePlainCustomFunctionPost
CategoryUncategorized
SlugPlainCustomFunctionPost
Process
  • Theme: Visual Studio
  • Language: Kuroco Smarty
*Paste the source code below into the text area.
StatusPublish
{* 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].

Image from Gyazo

Select plain-custom-endpoint-post, which you created earlier.

Image from Gyazo

Click [Try it out].

Image from Gyazo

Then, click [Execute].

Image from Gyazo

You should see the contents of the function displayed under "Response body".

Image from Gyazo

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.