SYS-CON MEDIA Authors: Sematext Blog, Liz McMillan, Elizabeth White, Carmen Gonzalez, Pat Romanski

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
The Japan External Trade Organization (JETRO) is a non-profit organization that provides business support services to companies expanding to Japan. With the support of JETRO's dedicated staff, clients can incorporate their business; receive visa, immigration, and HR support; find dedicated office space; identify local government subsidies; get tailored market studies; and more.
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...
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...
As the fourth industrial revolution continues to march forward, key questions remain related to the protection of software, cloud, AI, and automation intellectual property. Recent developments in Supreme Court and lower court case law will be reviewed to explain the intricacies of what inventions are eligible for patent protection, how copyright law may be used to protect application programming interfaces (APIs), and the extent to which trademark and trade secret law may have expanded relev...
Containerized software is riding a wave of growth, according to latest RightScale survey. At Sematext we see this growth trend via our Docker monitoring adoption and via Sematext Docker Agent popularity on Docker Hub, where it crossed 1M+ pulls line. This rapid rise of containers now makes Docker the top DevOps tool among those included in RightScale survey. Overall Docker adoption surged to 35 percent, while Kubernetes adoption doubled, going from 7% in 2016 to 14% percent.
Docker is sweeping across startups and enterprises alike, changing the way we build and ship applications. It's the most prominent and widely known software container platform, and it's particularly useful for eliminating common challenges when collaborating on code (like the "it works on my machine" phenomenon that most devs know all too well). With Docker, you can run and manage apps side-by-side - in isolated containers - resulting in better compute density. It's something that many developer...
In today's always-on world, customer expectations have changed. Competitive differentiation is delivered through rapid software innovations, the ability to respond to issues quickly and by releasing high-quality code with minimal interruptions. DevOps isn't some far off goal; it's methodologies and practices are a response to this demand. The demand to go faster. The demand for more uptime. The demand to innovate. In this keynote, we will cover the Nutanix Developer Stack. Built from the foundat...
In a recent survey, Sumo Logic surveyed 1,500 customers who employ cloud services such as Amazon Web Services (AWS), Microsoft Azure, and Google Cloud Platform (GCP). According to the survey, a quarter of the respondents have already deployed Docker containers and nearly as many (23 percent) are employing the AWS Lambda serverless computing framework. It's clear: serverless is here to stay. The adoption does come with some needed changes, within both application development and operations. Th...
Emil Sayegh is an early pioneer of cloud computing and is recognized as one of the industry's true veterans. A cloud visionary, he is credited with launching and leading the cloud computing and hosting businesses for HP, Rackspace, and Codero. Emil built the Rackspace cloud business while serving as the company's GM of the Cloud Computing Division. Earlier at Rackspace he served as VP of the Product Group and launched the company's private cloud and hosted exchange services. He later moved o...
Today, Kubernetes is the defacto standard if you want to run container workloads in a production environment. As we set out to build our next generation of products, and run them smoothly in the cloud, we needed to move to Kubernetes too! In the process of building tools like KubeXray and GoCenter we learned a whole bunch. Join this talk to learn how to get started with Kubernetes and how we got started at JFrog building our new tools. After the session you will know: How we got to Kuberne...
The Crypto community has run out of anarchists, libertarians and almost absorbed all the speculators it can handle, the next 100m users to join Crypto need a world class application to use. What will it be? Alex Mashinsky, a 7X founder & CEO of Celsius Network will discuss his view of the future of Crypto.
Docker and Kubernetes are key elements of modern cloud native deployment automations. After building your microservices, common practice is to create docker images and create YAML files to automate the deployment with Docker and Kubernetes. Writing these YAMLs, Dockerfile descriptors are really painful and error prone.Ballerina is a new cloud-native programing language which understands the architecture around it - the compiler is environment aware of microservices directly deployable into infra...
In his session at 20th Cloud Expo, Mike Johnston, an infrastructure engineer at Supergiant.io, will discuss how to use Kubernetes to setup a SaaS infrastructure for your business. Mike Johnston is an infrastructure engineer at Supergiant.io with over 12 years of experience designing, deploying, and maintaining server and workstation infrastructure at all scales. He has experience with brick and mortar data centers as well as cloud providers like Digital Ocean, Amazon Web Services, and Rackspace....
When Enterprises started adopting Hadoop-based Big Data environments over the last ten years, they were mainly on-premise deployments. Organizations would spin up and manage large Hadoop clusters, where they would funnel exabytes or petabytes of unstructured data.However, over the last few years the economics of maintaining this enormous infrastructure compared with the elastic scalability of viable cloud options has changed this equation. The growth of cloud storage, cloud-managed big data e...
Blockchain has shifted from hype to reality across many industries including Financial Services, Supply Chain, Retail, Healthcare and Government. While traditional tech and crypto organizations are generally male dominated, women have embraced blockchain technology from its inception. This is no more evident than at companies where women occupy many of the blockchain roles and leadership positions. Join this panel to hear three women in blockchain share their experience and their POV on the futu...