Spoiler Alert: it’s REALLY easy to add a REST API to your own Development on Windows desktop applications. Read along with us and we’ll show you exactly how easy it is! Expressjs is a fast, ‘unopinionated’ minimalist web framework for Node.js. It provides a great combination of features that make web application development fast and easy which would otherwise be much more time-consuming using only plain Node.js. ExpressJS can also make it very easy for us to build and expose fast and robust APIs for our users. Because of this powerful ease of use ExpressJS is a very popular framework among Nodejs’s developers.
Table of Contents
Are there any Delphi frameworks similar to ExpressJS?
We Delphi developers are a lucky bunch, blessed with a huge range of Delphi components and libraries and thankfully, inspired by the ExpressJS concept, we now have Opensource project called Horse which can be found at https://github.com/HashLoad/horse. Horse is a web framework for Delphi. Designed to ease things up for fast development in a minimalist way and yet achieving high performance.
Let’s compare ExpressJS with the Delphi Horse framework
ExpressJS :
[crayon-6767a2363656e596304195/]Horse:
[crayon-6767a23636577766494518/]very similar isn’t it? and it looks simple when making API route
What are the steps to create an application using Horse?
Here’s how to create an API server application, which is a bit similar to what can be done with expressjs. The steps are:
- Download or clone the repository [crayon-6767a23636579763138520/]
- Launch your Delphi IDE and Create new Application Console
- Open Project source and paste the following code:
- Create folder app/routes, so the folder’s structure became like below:
- Create a new unit file, name it
index.pas
- Create another unit and call it
employee.pas
Here is the Delphi example code for creating a REST API using the Horse framework
index.pas
[crayon-6767a2363657b609515574/]employee.pas
[crayon-6767a2363657c487677418/]Creating file API Path per file, making it easy for developers in further development or code troubleshoot. that’s it.
Now run the program, and point your browser at http://localhost:8080/apis/employees/3 , You will see the response as below:
[crayon-6767a2363657d588739225/]Get the latest news and updates on this Delphi forum page as well as links to several resource sites.
So, adding a REST API to your own applications really is easy isn’t it? Why not give it a try yourself? You can get all of the example source code from the following link: https://github.com/checkdigits/horse-API-Demo