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

Blog Feed Post

Instantly Build REST APIs with Server Code

The Appery.io 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 Appery.io 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 Appery.io. 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 Appery.io 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 Appery.io, 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: http://maxkatz.org and Twitter: @maxkatz.

Latest Stories
Moroccanoil®, the global leader in oil-infused beauty, is thrilled to announce the NEW Moroccanoil Color Depositing Masks, a collection of dual-benefit hair masks that deposit pure pigments while providing the treatment benefits of a deep conditioning mask. The collection consists of seven curated shades for commitment-free, beautifully-colored hair that looks and feels healthy.
The textured-hair category is inarguably the hottest in the haircare space today. This has been driven by the proliferation of founder brands started by curly and coily consumers and savvy consumers who increasingly want products specifically for their texture type. This trend is underscored by the latest insights from NaturallyCurly's 2018 TextureTrends report, released today. According to the 2018 TextureTrends Report, more than 80 percent of women with curly and coily hair say they purcha...
The textured-hair category is inarguably the hottest in the haircare space today. This has been driven by the proliferation of founder brands started by curly and coily consumers and savvy consumers who increasingly want products specifically for their texture type. This trend is underscored by the latest insights from NaturallyCurly's 2018 TextureTrends report, released today. According to the 2018 TextureTrends Report, more than 80 percent of women with curly and coily hair say they purcha...
We all love the many benefits of natural plant oils, used as a deap treatment before shampooing, at home or at the beach, but is there an all-in-one solution for everyday intensive nutrition and modern styling?I am passionate about the benefits of natural extracts with tried-and-tested results, which I have used to develop my own brand (lemon for its acid ph, wheat germ for its fortifying action…). I wanted a product which combined caring and styling effects, and which could be used after shampo...
The precious oil is extracted from the seeds of prickly pear cactus plant. After taking out the seeds from the fruits, they are adequately dried and then cold pressed to obtain the oil. Indeed, the prickly seed oil is quite expensive. Well, that is understandable when you consider the fact that the seeds are really tiny and each seed contain only about 5% of oil in it at most, plus the seeds are usually handpicked from the fruits. This means it will take tons of these seeds to produce just one b...
Steaz, the nation's top-selling organic and fair trade green-tea-based beverage company, announces its 2017 "Mind. Body. Soul." tour, which will bring authentic experiences inspired by the brand's signature Mind. Body. Soul. tagline to life across the country. The tour will inform, educate, inspire and entertain through events, digital activations and partner-curated experiences developed to support the three pillars of complete health and wellness.
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...