SYS-CON MEDIA Authors: Zakia Bouachraoui, Carmen Gonzalez, Yeshim Deniz, Pat Romanski, Gary Arora

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
Public clouds dominate IT conversations but the next phase of cloud evolutions are "multi" hybrid cloud environments. The winners in the cloud services industry will be those organizations that understand how to leverage these technologies as complete service solutions for specific customer verticals. In turn, both business and IT actors throughout the enterprise will need to increase their engagement with multi-cloud deployments today while planning a technology strategy that will constitute a ...
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...
Every organization is facing their own Digital Transformation as they attempt to stay ahead of the competition, or worse, just keep up. Each new opportunity, whether embracing machine learning, IoT, or a cloud migration, seems to bring new development, deployment, and management models. The results are more diverse and federated computing models than any time in our history.
Andrew Keys is co-founder of ConsenSys Enterprise. He comes to ConsenSys Enterprise with capital markets, technology and entrepreneurial experience. Previously, he worked for UBS investment bank in equities analysis. Later, he was responsible for the creation and distribution of life settlement products to hedge funds and investment banks. After, he co-founded a revenue cycle management company where he learned about Bitcoin and eventually Ethereum.
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...
Isomorphic Software is the global leader in high-end, web-based business applications. We develop, market, and support the SmartClient & Smart GWT HTML5/Ajax platform, combining the productivity and performance of traditional desktop software with the simplicity and reach of the open web. With staff in 10 timezones, Isomorphic provides a global network of services related to our technology, with offerings ranging from turnkey application development to SLA-backed enterprise support. Leadin...
Concerns about security, downtime and latency, budgets, and general unfamiliarity with cloud technologies continue to create hesitation for many organizations that truly need to be developing a cloud strategy. Hybrid cloud solutions are helping to elevate those concerns by enabling the combination or orchestration of two or more platforms, including on-premise infrastructure, private clouds and/or third-party, public cloud services. This gives organizations more comfort to begin their digital tr...
On-premise or off, you have powerful tools available to maximize the value of your infrastructure and you demand more visibility and operational control. Fortunately, data center management tools keep a vigil on memory contestation, power, thermal consumption, server health, and utilization, allowing better control no matter your cloud's shape. In this session, learn how Intel software tools enable real-time monitoring and precise management to lower operational costs and optimize infrastructure...
Data center, on-premise, public-cloud, private-cloud, multi-cloud, hybrid-cloud, IoT, AI, edge, SaaS, PaaS... it's an availability, security, performance and integration nightmare even for the best of the best IT experts. Organizations realize the tremendous benefits of everything the digital transformation has to offer. Cloud adoption rates are increasing significantly, and IT budgets are morphing to follow suit. But distributing applications and infrastructure around increases risk, introdu...
Bill Schmarzo, author of "Big Data: Understanding How Data Powers Big Business" and "Big Data MBA: Driving Business Strategies with Data Science" is responsible for guiding the technology strategy within Hitachi Vantara for IoT and Analytics. Bill brings a balanced business-technology approach that focuses on business outcomes to drive data, analytics and technology decisions that underpin an organization's digital transformation strategy. Bill has a very impressive background which includes ...
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...
DevOps has long focused on reinventing the SDLC (e.g. with CI/CD, ARA, pipeline automation etc.), while reinvention of IT Ops has lagged. However, new approaches like Site Reliability Engineering, Observability, Containerization, Operations Analytics, and ML/AI are driving a resurgence of IT Ops. In this session our expert panel will focus on how these new ideas are [putting the Ops back in DevOps orbringing modern IT Ops to DevOps].
While a hybrid cloud can ease that transition, designing and deploy that hybrid cloud still offers challenges for organizations concerned about lack of available cloud skillsets within their organization. Managed service providers offer a unique opportunity to fill those gaps and get organizations of all sizes on a hybrid cloud that meets their comfort level, while delivering enhanced benefits for cost, efficiency, agility, mobility, and elasticity.
Most organizations are awash today in data and IT systems, yet they're still struggling mightily to use these invaluable assets to meet the rising demand for new digital solutions and customer experiences that drive innovation and growth. What's lacking are potent and effective ways to rapidly combine together on-premises IT and the numerous commercial clouds that the average organization has in place today into effective new business solutions. New research shows that delivering on multicloud e...
On-premise or off, you have powerful tools available to maximize the value of your infrastructure and you demand more visibility and operational control. Fortunately, data center management tools keep a vigil on memory contestation, power, thermal consumption, server health, and utilization, allowing better control no matter your cloud's shape. In this session, learn how Intel software tools enable real-time monitoring and precise management to lower operational costs and optimize infrastructure...