Effective Strategies for Optimizing Web API Performance in AppianKristijan Zdelarec
In today’s connected world, the ability to access and share data across different systems and platforms is crucial for businesses and individuals alike. Web APIs (Application Programming Interfaces) have become the backbone of this interconnectedness, allowing different systems to communicate and share data seamlessly. Here are some tips that will help you unlock the full potential of your Appian platform with the power and versatility of web APIs, seamlessly connecting your system to a wide range of external data sources and services.
Start a process
When building a web API in Appian, it can be easy to get overwhelmed by the many possibilities available to you. While it may be tempting to put all of your business logic in the web API expression editor, this approach has a major drawback: there is no way to debug your code. To overcome this limitation, it is recommended to start a process instead.
Starting a process in Appian allows for less code in your API definition, better debugging capabilities, and an increased number of functionalities. The process can be started from a web API by calling the startProcess function and providing the process pointer constant and process parameters in dictionary form. Here is a simple example:
By starting a process, you can take advantage of all the debugging and monitoring features that Appian provides, making it easier to troubleshoot and improve your API. Additionally, processes allow you to encapsulate and organize your business logic in a way that makes it easier to maintain and understand. So next time you’re building a web API in Appian, consider starting a process to simplify your code and improve your debugging capabilities.
Control response messages
When building a web API, it is important to be able to communicate effectively with client devices and other web services. One way to ensure standardized communication is by defining and controlling how response messages are sent in case of a process success or failure.
In Appian, you can control your response messages by providing expressions for the onSuccess and onError parameters in the startProcess function. This allows you to create a generic message template builder that can generate response messages, as shown in the following example:
By defining and controlling your response messages, you can ensure that your API is communicating effectively with client devices and other web services. Additionally, it can also help to avoid potential issues with communication and ensure the smooth working of your API. It’s the best practice to handle response messages in case of an error or success in your Appian web API.
Use CDTs as a request data holder
After receiving a request and starting a process, it’s important to be able to parse the request and use the data for later operations. In order to avoid any additional operations in the web API definition, the request data needs to be passed to the process as a process parameter, as previously discussed. To ensure that the process can accept the request message, a process variable with the “parameter” option should be defined.
Once the variable is introduced, the request message is available to use in the process. However, the request message is often just a string of information, which can make parsing difficult. To simplify this task, you can use CDTs (Custom Data Types) as data holders. By using the fromJson function in a ScriptTask node, you can transfer the request message from text to a CDT, and save the result in a new variable with a type of CDT.
By using CDTs as a request data holder, you can make the data more accessible and easier to use throughout the process, and avoid the complexity of parsing the request message. This technique streamlines your process, making it more efficient and less prone to errors.
A well-designed backend system must guarantee data consistency and accuracy. When accepting request messages from client devices or other web services, it’s important to never assume that the data has been validated on the client side. After parsing a request message, it’s the best practice to validate all crucial data to ensure it conforms to the technical specification.
Data validation can be done in a variety of ways, from validating individual parameters to whole objects. This can include validating the length, type, and format of the data. While the specifics of data validation will depend on the specific data and use case, the ultimate goal is always to ensure consistency and accuracy.
It’s important to validate data in your Appian web API to prevent errors, inconsistencies, and inaccuracies in your process. Invalid data can cause unexpected behavior in your process and even lead to critical failures. By implementing data validation, you can ensure that your API is reliable and consistent.
When designing processes for a web API, it is important to consider the potential for errors and how to handle them effectively. In Appian, a process can consist of multiple nodes connected by activity chaining. If the process has many nodes and is at risk of exceeding the node limit, one solution is to use the Start Process Smart Service to start subprocesses. However, if an error occurs in a subprocess, the parent process may not be aware of it and will continue as if the process was successful. This can lead to unexpected behavior and critical failures.
To prevent this, it is important to properly handle errors that arise in subprocesses. One way to do this is by introducing a Boolean variable that represents successful execution. By initializing this variable as false and setting it to true once the process finishes successfully, one can monitor the parent process for child process failures. By exposing the success variable to the parent process, the XOR node can be used to determine if the execution was successful.
To ensure that errors are handled effectively, it is recommended to prepare a response message on the parent process level that will be returned to the client device in case of an error. This allows for effective communication of the error to the client and handling it in a controlled manner. By properly handling errors in Appian processes, the reliability and consistency of the API can be ensured.
In conclusion, building a web API in Appian requires careful consideration of various factors to ensure reliability and consistency. By following the tips discussed in this blog, you can create a robust system that can always deliver correct information and has the capability to troubleshoot and handle crucial errors. By using best practices like starting a process, controlling and handling response messages, using CDTs as a request data holder, validating data, and handling errors effectively, you can take your web APIs to the next level of performance and efficiency. If you have any further inquiries, don’t hesitate to contact us for additional support and guidance.