Coder Social home page Coder Social logo

appengine's Introduction

App Engine JavaScript SDK

Welcome to App Engine for JavaScript! With App Engine, you can build web applications using the JavaScript programming language, and take advantage of the many libraries, tools and frameworks for JavaScript that professional developers use to build world-class web applications. Your JavaScript application runs on Google's scalable infrastructure on top of Java and Rhino, and uses large-scale persistent storage and services.

This is a community project, not affiliated in any way with Google.

This SDK is part of the Nitro ecosystem of Web Application development resources. The SDK tracks the latest developments in the CommonJS group.

Design and Implementation

The SDK is powered by Rhino on top of App Engine Java. However, the API is based on App Engine Python. In our view, the design of the Python API is closer to the JavaScript world.

As a result, a developer can consult the App Engine Python documentation to work effectively with the JavaScript SDK.

We use JavaScript coding conventions. Python names like 'this_is_a_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).

Datastore

The Python ext/db api is supported. The API is slightly different to better fit 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().limit(3).fetch();

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);
}

URL Fetch

var fetch = require("google/appengine/api/urlfetch").fetch;

var response = fetch("http://www.appenginejs.org"),
    html = response.content.decodeToString("UTF-8");

Images

var images = require("google/appengine/api/images");
var i = images.resize(params.image.data, 640, 480);

Email

var EmailMessage = require("google/appengine/api/mail").EmailMessage;

new EmailMessage({
    sender: "[email protected]",
    to: "[email protected]",
    subject: "My email",
    body: template.render(params)
}).send();

Memcache

var memcache = require("google/appengine/api/memcache");

var fragment = memcache.get("fragment");
if (!fragment) {
    ...
    memcache.set("fragment", fragment);
}

Users

var users = require("google/appengine/api/users");

var user = users.getCurrentUser();

if (users.isCurrentUserAdmin()) {
    ...
}

var url = user.createLoginURL();

Task Queue

var taskqueue = require("google/appengine/api/labs/taskqueue");

taskqueue.add({url: "/worker", method: "GET", params: {par1: "hello", par2: "world"}});  

var task = new Task({url: "/worker", method: "GET", params: {par1: "hello", par2: "world"}});
task.add("customqueue");

Forms

var Article = require("article").Article,
    ModelForm = require("google/appengine/ext/db/forms").ModelForm,
    ArticleForm = ModelForm(Article);

    ...
    
var form = new ArticleForm(params, {instance: article});
    ...
    form.save();

Example

For an example of the usage of this library have a look at the blog-gae example.

Component status

This library is under construction but usable. Substantial parts of the Python API are converted.

  • google/appengine/api/memcache: 80% (usable)
  • google/appengine/api/urlfetch: 80% (usable)
  • google/appengine/api/mail: 60% (usable)
  • google/appengine/api/images: 60% (usable)
  • google/appengine/api/users: 80% (usable)
  • google/appengine/api/labs/taskqueue: 80% (usable)
  • google/appengine/ext/db: 80% (usable, expect minor API changes)
  • google/appengine/ext/db/forms: 30% (expect API changes)
  • google/appengine/ext/blobstore: 40% (usable)

Credits

Google App Engine

This is a community project, not affiliated in any way with Google.

Google App Engine is a service of Google, Inc. Copyright (c) 2009 Google, all rights reserved.

License

Copyright (c) 2009 George Moschovitis, http://gmosx.com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

appengine's People

Contributors

cadorn avatar gmosx avatar rsaccon avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.