DZone
Cloud Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Cloud Zone > AppengineJS: JavaScript Comes to GAE

AppengineJS: JavaScript Comes to GAE

Mitch Pronschinske user avatar by
Mitch Pronschinske
·
Jun. 02, 10 · Cloud Zone · Interview
Like (0)
Save
Tweet
27.16K Views

Join the DZone community and get the full member experience.

Join For Free
Although there's no JavaScript SDK made by Google for the App Engine platform, a new port of the GAE Python SDK to JavaScript called AppengineJS facilitates the construction of apps for GAE that are written in the language that all web developers are familiar with.  The port uses Rhino (the JVM implementation of JavaScript) on top of App Engine Java, but the API is based on App Engine Python because it's a scripting language like JS.

In a blog this week, George Moschovitis, one of the project developers, said that his project has recently garnered an intense amount of interest, and he had a couple of answers to readers' comments.  He said that if you already know Python or Java, you should stick with those SDKs, which are supported by Google.  The App Engine Python documentation should work effectively for the JavaScript SDK.  

The AppengineJS documentation explains that they use JavaScript coding conventions:

Python names like 'thisisa_name' are converted to JavaScript names like 'thisIsAName'. Moreover all delete() functions are renamed to .remove() functions to avoid collisions with the delete keyword (a DELETE() alias is also provided but it's uses is not recommended and may be deprecated in the future).

For the GAE Datastore, the the Python ext/db api is supported, but the API has been slightly modified to be more compatible with JavaScript:
var db = require("google/appengine/ext/db");

var Category = db.Model("Category", {
label: new db.StringProperty(),
category: new db.ReferenceProperty({referenceClass: Category})
});

var c = new Category({keyName: "news", label: News"});
c.put();
var key = ...
var c1 = Category.get(key);
var c2 = Category.getByKeyName("news");
var categories = Category.all().fetch(3);
...
var comments = Comment.all().ancestor(article).order("-created").withCursor(cursor).fetch(10);

Here's a sample of the AppengineJS documentation pertaining to the Blobstore:

Form:
var blobstore = require("google/appengine/api/blobstore");

exports.GET = function(env) {
return {data: {
uploadURL: blobstore.createUploadUrl("/test")
}}
}

<form action="{uploadURL}" method="POST" enctype="multipart/form-data">
<p>
<input type="file" name="file" />
</p>
<p>
<button type="submit">Upload</button>
</p>
</form>
Upload:
var blobstore = require("google/appengine/api/blobstore");

exports.GET = function(env) {
return {data: {
uploadURL: blobstore.createUploadUrl("/save")
}}
}
Save:
var blobstore = require("google/appengine/api/blobstore");

exports.POST = function(env) {
var blobs = blobstore.getUploadedBlobs(env);

return {
status : 303,
headers : {
"Location": "/serve?key=" + blobs.file.toString()
}
};
}
Serve:
var blobstore = require("google/appengine/api/blobstore");

exports.GET = function(env) {
var params = new Request(env).GET();
return blobstore.serve(params.key, env);
}

Also covered in the AppengineJS docs are URL Fetches, Images, Email, Memcache, Users, Task Queue, XMPP, Forms, Quota, and OAuth.  The library is still under development, but it's definitely usable right now.  Here is the breakdown of the level of Python API conversions:

    •    google/appengine/api/memcache: 90% (usable)
    •    google/appengine/api/urlfetch: 80% (usable)
    •    google/appengine/api/mail: 80% (usable)
    •    google/appengine/api/images: 60% (usable)
    •    google/appengine/api/users: 90% (usable)
    •    google/appengine/api/labs/taskqueue: 80% (usable)
    •    google/appengine/ext/db: 80% (usable, expect minor API changes)
    •    google/appengine/ext/db/forms: 60% (usable, expect API changes)
    •    google/appengine/api/xmpp: 80% (usable)
    •    google/appengine/ext/blobstore: 50% (usable)
    •    google/appengine/api/oauth: 90% (not tested)

You can download AppengineJS at GitHub.  The SDK is part of the Nitro Ecosystem and tracks the latest developments in the CommonJS group.
JavaScript

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Use Lambda Function URL To Write a Serverless App Backed by DynamoDB
  • Querying Kafka Topics Using Presto
  • A Simple Guide to Heaps, Stacks, References, and Values in JavaScript
  • How Database B-Tree Indexing Works

Comments

Cloud Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo