SYS-CON MEDIA Authors: Liz McMillan, Carmen Gonzalez, Zakia Bouachraoui, Roger Strukhoff, David Linthicum

Blog Feed Post

Instantly Build REST APIs with Server Code

The Server Code allows to build any app logic and instantly expose it via REST APIs. You use Javascript to write the script which runs on the server. You don’t need to worry about deploying or running any servers, all is done in the cloud. An example is the best way to show it, so let’s do that.

To keep the example simple, let’s say we wan to build an API (script) that takes a developer’s name returns a greeting and also returns the time when the greeting occurred. It’s basically your HelloWorld example.

To create a new Server Code script you just need to click Create script button:

Screen Shot 2015-04-16 at 2.29.54 PM

When the script editor opens, on the left-hand side is the area to write the script and on the right-hand side is the area where you can test the script (you can hide either area by clicking Hide Editor or Hide Test buttons).

Screen Shot 2015-04-16 at 2.33.57 PM

Let’s look closer at the script.

var devName = request.get("devName");
var greeting = "Hello " + devName + "!";
var time = moment().format();

response.success ({"result":greeting, "time":time}, "application/json");

  • The 1st line looks in the request and retrieves the devName parameter passed in the API call
  • The 2nd line creates a greeting string.
  • The 3rd line uses Moment.js library to get the current time.
  • The 4th line returns the response in JSON format. This is the REST API service response.

You might be wondering how can we use Moment.js if the library is not loaded/referenced anywhere? In addition to writing scripts, you can also use libraries. You can load an existing 3rd party library or you can write your own library. Then you can make the script be dependent on one or more libraries.

Screen Shot 2015-04-16 at 2.43.19 PM

As you can see, moment.js is available in Server Code out-of-the-box. You only need to mark the library as dependency for this script:

Screen Shot 2015-04-16 at 2.45.06 PM

The script is simple and the logic is instantly exposed via a REST API. There is nothing extra you need to do. Just write the script logic.

The beauty is that you just built a new REST API.

Click REST information tab to see the API URL:

Screen Shot 2015-04-16 at 2.49.26 PM

  • The Service URL section shows the end point you can use to invoke the service.
    • Optionally, you can also give the script an alias. The alias will replace the script id in the URL.
  • The Description URL is an end point to service documentation. If someone wants to learn what the service, they cna invoke this API to get information about the service.

Before using the service in an app you want to test the API. That’s easy to do. On the right-hand side you will see two tabs: Run and Script parameters.

Screen Shot 2015-04-16 at 2.54.20 PM

As our script takes one parameter: devName you will add the parameter and specify a default value for testing. Now you are ready to test:

Screen Shot 2015-04-16 at 2.54.52 PM

Clicking Save and run button invokes the script and shows the result. Now that you know the script works, it’s time to use the API.

There are many ways you can invoke the script. You can use a curl command, or use the Postman plugin in Chrome browser:

Screen Shot 2015-04-16 at 4.06.21 PM

You can as easily use it when building a mobile app in In fact, you can automatically generate the service on the client from inside the App Builder:

Screen Shot 2015-04-16 at 4.08.50 PM

Once the service is generated, you can test the service (same way you test the service in Postman):

Screen Shot 2015-04-16 at 4.09.56 PM

You can also quickly build a mobile app with the API you just designed:

Screen Shot 2015-04-16 at 4.19.32 PM

With Server Code, you can quickly build APIs that wrap any custom app logic in Javascript. Server Code offers extensive API to help you develop the script. There is API to connect to Database, send push notifications, and you can also integrate with any external systems or 3rd party APIs.

Read the original blog entry...

More Stories By Max Katz

Max Katz heads Developer Relations for, a cloud-based mobile app platform. He loves trying out new and cool REST APIs in mobile apps. Max is the author of two books “Practical RichFaces” (Apress 2008, 2011), DZone MVB (Most Valuable Blogger), and is a frequent speaker at developer conferences. You can find out what Max is up to on his blog: and Twitter: @maxkatz.

Latest Stories
The platform combines the strengths of Singtel's extensive, intelligent network capabilities with Microsoft's cloud expertise to create a unique solution that sets new standards for IoT applications," said Mr Diomedes Kastanis, Head of IoT at Singtel. "Our solution provides speed, transparency and flexibility, paving the way for a more pervasive use of IoT to accelerate enterprises' digitalisation efforts. AI-powered intelligent connectivity over Microsoft Azure will be the fastest connected pat...
There are many examples of disruption in consumer space – Uber disrupting the cab industry, Airbnb disrupting the hospitality industry and so on; but have you wondered who is disrupting support and operations? AISERA helps make businesses and customers successful by offering consumer-like user experience for support and operations. We have built the world’s first AI-driven IT / HR / Cloud / Customer Support and Operations solution.
ScaleMP is presenting at CloudEXPO 2019, held June 24-26 in Santa Clara, and we’d love to see you there. At the conference, we’ll demonstrate how ScaleMP is solving one of the most vexing challenges for cloud — memory cost and limit of scale — and how our innovative vSMP MemoryONE solution provides affordable larger server memory for the private and public cloud. Please visit us at Booth No. 519 to connect with our experts and learn more about vSMP MemoryONE and how it is already serving some of...
Darktrace is the world's leading AI company for cyber security. Created by mathematicians from the University of Cambridge, Darktrace's Enterprise Immune System is the first non-consumer application of machine learning to work at scale, across all network types, from physical, virtualized, and cloud, through to IoT and industrial control systems. Installed as a self-configuring cyber defense platform, Darktrace continuously learns what is ‘normal' for all devices and users, updating its understa...
Codete accelerates their clients growth through technological expertise and experience. Codite team works with organizations to meet the challenges that digitalization presents. Their clients include digital start-ups as well as established enterprises in the IT industry. To stay competitive in a highly innovative IT industry, strong R&D departments and bold spin-off initiatives is a must. Codete Data Science and Software Architects teams help corporate clients to stay up to date with the mod...
As you know, enterprise IT conversation over the past year have often centered upon the open-source Kubernetes container orchestration system. In fact, Kubernetes has emerged as the key technology -- and even primary platform -- of cloud migrations for a wide variety of organizations. Kubernetes is critical to forward-looking enterprises that continue to push their IT infrastructures toward maximum functionality, scalability, and flexibility. As they do so, IT professionals are also embr...
Platform9, the leader in SaaS-managed hybrid cloud, has announced it will present five sessions at four upcoming industry conferences in June: BCS in London, DevOpsCon in Berlin, HPE Discover and Cloud Computing Expo 2019.
At CloudEXPO Silicon Valley, June 24-26, 2019, Digital Transformation (DX) is a major focus with expanded DevOpsSUMMIT and FinTechEXPO programs within the DXWorldEXPO agenda. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive over the long term. A total of 88% of Fortune 500 companies from a generation ago are now out of business. Only 12% still survive. Similar percentages are found throug...
When you're operating multiple services in production, building out forensics tools such as monitoring and observability becomes essential. Unfortunately, it is a real challenge balancing priorities between building new features and tools to help pinpoint root causes. Linkerd provides many of the tools you need to tame the chaos of operating microservices in a cloud native world. Because Linkerd is a transparent proxy that runs alongside your application, there are no code changes required. I...
In his general session at 21st Cloud Expo, Greg Dumas, Calligo’s Vice President and G.M. of US operations, discussed the new Global Data Protection Regulation and how Calligo can help business stay compliant in digitally globalized world. Greg Dumas is Calligo's Vice President and G.M. of US operations. Calligo is an established service provider that provides an innovative platform for trusted cloud solutions. Calligo’s customers are typically most concerned about GDPR compliance, application p...
Modern software design has fundamentally changed how we manage applications, causing many to turn to containers as the new virtual machine for resource management. As container adoption grows beyond stateless applications to stateful workloads, the need for persistent storage is foundational - something customers routinely cite as a top pain point. In his session at @DevOpsSummit at 21st Cloud Expo, Bill Borsari, Head of Systems Engineering at Datera, explored how organizations can reap the bene...
"NetApp's vision is how we help organizations manage data - delivering the right data in the right place, in the right time, to the people who need it, and doing it agnostic to what the platform is," explained Josh Atwell, Developer Advocate for NetApp, in this interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
Druva is the global leader in Cloud Data Protection and Management, delivering the industry's first data management-as-a-service solution that aggregates data from endpoints, servers and cloud applications and leverages the public cloud to offer a single pane of glass to enable data protection, governance and intelligence-dramatically increasing the availability and visibility of business critical information, while reducing the risk, cost and complexity of managing and protecting it. Druva's...
Kubernetes as a Container Platform is becoming a de facto for every enterprise. In my interactions with enterprises adopting container platform, I come across common questions: - How does application security work on this platform? What all do I need to secure? - How do I implement security in pipelines? - What about vulnerabilities discovered at a later point in time? - What are newer technologies like Istio Service Mesh bring to table?In this session, I will be addressing these commonly asked ...
BMC has unmatched experience in IT management, supporting 92 of the Forbes Global 100, and earning recognition as an ITSM Gartner Magic Quadrant Leader for five years running. Our solutions offer speed, agility, and efficiency to tackle business challenges in the areas of service management, automation, operations, and the mainframe.