• Stars
    star
    152
  • Rank 244,685 (Top 5 %)
  • Language
    JavaScript
  • Created over 13 years ago
  • Updated over 10 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A tiny JavaScript web framework targeted for Google App Engine

A tiny JavaScript web framework targeted for Google App Engine

Prototyping applications is as easy as writing some JSON:

var apejs = require("apejs.js");
apejs.urls = {
    "/": {
        get: function(request, response) {
            response.getWriter().println("Hello World!");
        }
    },
    "/foo": {
        get: function(request, response) {
            request.getSession(true);
        }
    },
    "/recipes/([a-zA-Z0-9_]+)" : {
        get: function(request, response, matches) {
            response.getWriter().println(matches[1]);
        },
        post: function(request, response) {
            // do something during POST request
        }
    }
}

Reaching http://yoursite.com/ will output Hello World!, accessing http://yoursite.com/foo will start a new session and going to http://yoursite.com/recipes/my-fantastic-recipe will show you my-fantastic-recipe.

You can leverage the entire Java API (Rhino) directly through JavaScript, avoiding re-compilation times in favor of raw scripting power!

Idea behind ApeJS

The idea behind ApeJS is to provide a tiny framework for developing Google App Engine websites using the JavaScript language. There are other JS frameworks out there that you could use with App Engine - RingoJS and AppEngineJS are extremely well made - but I needed something more simple, something that didn't come with tons of libraries and that could let me prototype applications really quickly (think of web.py) and so I created ApeJS.

How to start

  1. Clone ApeJS by simply typing git clone [email protected]:lmatteis/apejs.git in a terminal.

  2. Download the latest App Engine Java SDK from the App Engine website. Unzip, open the folder and navigate to the lib/user/ directory where you will find an appengine-api-1.0-sdk-x.x.x.jar file. Copy this jar file to the your war/WEB-INF/lib directory from within the ApeJS dir we cloned in the earlier step.

  3. You're pretty much set. All you have to do is run dev_appserver.sh (or .cmd, found in the App Engine Java SDK) against the war directory of your ApeJS project.

  4. The main file you need to worry about is main.js. This is where all the handlers for specific urls are called. The examples already in there should get you started.

  5. An important folder you want to keep your eyes on is the /public/ directory. All your static content should go in here, stylesheets, images etc. So when you access http://yoursite.com/image.jpg the server will look inside /public/image.jpg for it.

Importing external JS files

Importing external JS files is quite easy thanks to require().

To include ApeJS modules (located under WEB-INF/modules/) you can do:

var googlestore = require("googlestore.js");

Otherwise you can include things from within your app directory by simply adding a ./ in front of the filename:

var myfile = require("./myfile.js");

require() will simply evaluate the contents of the JavaScript file and only expose whatever you assign exports with. This is how CommonJS implements so you could simply require CommonJS modules and they should work.

Some templating

will add some examples using mustache.js

Google Datastore

I'm trying to implement a really basic abstraction around the low-level Google datastore API. You can read the code under WEB-INF/modules/googlestore.js. In order to work with the datastore, first you need to include it in your file.

var googlestore = require("googlestore.js");

To create an entity and store it in the datastore you do:

var e = googlestore.entity("person", {
    "name": "Luca",
    "age": 25,
    "gender": "female",
    "nationality: "Italian"
});

// save the entity to the datastore
var key = googlestore.put(e);

You get an entity from the datastore by using a key:

// creating a key by ID
var key = googlestore.createKey("person", 15);

// get the entity from the datastore
var person = googlestore.get(key);

Listing more entities is done by using a query:

// selecting youngest 5 adult males as an array
var people = googlestore.query("person")
    .filter("gender", "=", "male")
    .filter("age", ">=", 18)
    .sort("age", "ASC")
    .fetch(5);

To get properties of an entity use the following method:

person.getProperty("gender");

Finally, there are a couple of key points to keep in mind when using the Datastore API:

  • Filtering Or Sorting On a Property Requires That the Property Exists
  • Inequality Filters Are Allowed on One Property Only
  • Properties in Inequality Filters Must Be Sorted before Other Sort Orders

http://code.google.com/appengine/docs/java/datastore/queries.html

More to come ...

More Repositories

1

torrent-net

Distributed search engines using BitTorrent and SQLite
C
1,013
star
2

peer-tweet

Decentralized feeds using BitTorrent's DHT. Idea from Arvid and The_8472 "DHT RSS feeds" http://libtorrent.org/dht_rss.html
JavaScript
880
star
3

next-13-layout-transitions

TypeScript
161
star
4

redux-statecharts

Redux statecharts
JavaScript
123
star
5

hckr.it

Hacker News clone for CouchDB
JavaScript
99
star
6

node-trello

Node wrapper for Trello's HTTP API.
JavaScript
98
star
7

redux-tdd

Redux TDD: Dot-chaining syntax for doing TDD with redux by composing unit tests as if they were integration tests
JavaScript
94
star
8

dmt

Decentralized Mutable Torrents reference implementation
JavaScript
75
star
9

behavioral

Behavioral Programming for JavaScript
JavaScript
73
star
10

react-behavioral

#BehavioralProgramming for React
JavaScript
55
star
11

ldstatic

Host your Linked Data for free, as static pages, using a variety of providers (GitHub Pages, Google Code, Google Drive, etc.), and run SPARQL queries using a basic Linked Data Fragment client.
JavaScript
18
star
12

void-graph

VoID Linked Data graph diagram displayed using JavaScript and SVG
JavaScript
17
star
13

access2couch

A command-line utility for Windows, that pushes a MS Access database to a CouchDB instance. Written in Node.js
JavaScript
10
star
14

waku-page-transitions

Framer motion page transitions with Waku React Server Components
TypeScript
7
star
15

restpark

Minimal RESTful API for querying RDF triples
CSS
7
star
16

redux-behavioral

Behavioral Programming for Redux
JavaScript
6
star
17

behavioral-programming-talk

Behavioral Programming talk at ReactJS day #BehavioralProgramming
5
star
18

jquery-report

Allows you to visualize an HTML Table out of JSON
JavaScript
5
star
19

bitcoin-notify

Notify when new places accepting Bitcoin have been added to OpenStreetMap
JavaScript
4
star
20

blogger-skeleton

Having troubles with creating Blogger themes? I created this skeleton to get you started.
4
star
21

genebanks

Genebanks Linked Data!
JavaScript
3
star
22

seed-couchapp

Couchapp for http://seeds.iriscouch.com/
JavaScript
2
star
23

grinfo-tumblr

A tumblr theme based on Twitter Bootstrap
2
star
24

middleend

some middleend!
PHP
2
star
25

smark

Create beautiful presentation slides with Markdown
JavaScript
2
star
26

seed-scraper

scrape genebanks websites for accession data
JavaScript
2
star
27

linked-data-node

A Linked Data frontend for SPARQL endpoints written in Node.js
JavaScript
2
star
28

romajs

JavaScript User Group & Meetup Roma -> https://plus.google.com/communities/114324393897443067092
JavaScript
2
star
29

json-compressor

Removes whitespace and JavaScript-style comments from a JSON string.
JavaScript
1
star
30

mealo

this is personal stuff! leave now!
JavaScript
1
star
31

kudos

something interesting p2p
JavaScript
1
star
32

ascetica-ines

PHP
1
star
33

resume

my resume :)
CSS
1
star
34

bttrkr

JavaScript
1
star
35

slides

My slides
TeX
1
star
36

human

A little irc bot that loads some data
JavaScript
1
star
37

seedhub

a seedhub is a seedhub no?
JavaScript
1
star
38

grinfo.net

Site for bio-informatics
JavaScript
1
star
39

mustache-rdf

Mustache RDF. Templating for RDF
1
star
40

romapingpong

Rome ping pong
JavaScript
1
star
41

finland-talk

https://lmatteis.github.io/finland-talk
1
star
42

selectjs-api

Documentation for the selectjs.com api
1
star
43

human-chiglug

Couchapp for http://chiglug.tk that shows data generated by the *human* bot
JavaScript
1
star
44

milu

An italian cooking site
JavaScript
1
star
45

waku-infinite-scroll

TypeScript
1
star