Have an amazing solution built in RAD Studio? Let us know. Looking for discounts? Visit our Special Offers page!
CodeDelphiIDERAD Studio

How Easy Is It To Add A REST API To Your Own Apps?

smartmockups kpve9reo

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.

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 :

Horse:

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
  • 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:
How Easy Is It To Add A REST API To Your Own Apps REST API paths
  • 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

employee.pas

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:


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

See What's New in 12.2 Athens See What's New in 12.2 Athens Dev Days of Summer 2-24

Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial   Upgrade Today

   Free Delphi Community Edition   Free C++Builder Community Edition

About author

Senior Software Engineer | Delphi/FreePascal Enthusiast | Linux/ Unix Enthusiast

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

IN THE ARTICLES