makeapi

MakeAPI for Webmaker

MakeAPI

Execute npm install in the application directory:

Copy and edit your .env file. -- This should never be committed to the repo.

cp .env.sample .env

Before you start your Node.js server, you'll need to run Redis, MongoDB and ElasticSearch

Assuming Redis, MongoDB and ElasticSearch are running at the specified places in your .env file simply running node server.js from the root should start the server.

By default the server will run at http://localhost:5000. You can change this by adding PORT= to your .env file.

Right now there is a small node app in test/test-make-client.js that will require in the API and make a sample create request. This is reliant upon the the entire repo being included down and not being pulled in through NPM. Eventually there will be tests not reliant on this.

HTTP Method Path Action Notes
POST /api/make Create Make If Post Data is a valid Make, it creates one and returns it with the _id and __v populated.
GET /api/make/:id Find a single Make Expects the last path element to be a valid ObjectId
PUT /api/make/:id Update a Make The Make must already exist and the __v must be the same as the current version on the server. This is an implementation of optimistic locking.
DELETE /api/make/:id Deletes a Make The effect is that of a delete operation, though the Make is actually only marked as deleted using the deletedAt timestamp.
POST /api/makes/search Find makes by search criteria

Searches for makes using elasticsearch. The body of your request must use elastic search's Query DSL and Content-Type must be application/json

  jQuery.ajax({
    type: "POST",
    url: "/api/make",
    data: {
      "url": "http://thimble.webmadecontent.org/abcd.html",
      "contentType": "text/html",
      "goal": "The goal of this lesson is to learn about img, p and blah tags...",
      "title": "Animal something-or-other",
      "locale": "en_us",
      "tags": ["awesome"],
      "privateTags": ["webmaker.org:project", "skill:css"],
      "description": "This handy HTML template makes it easy to quickly create your own text and image mashup, then publish it for sharing via Facebook, Tumblr or any web page. Your 15 seconds of internet fame await!",
      "author": "swex@mozilla.com",
      "contentAuthor": "swex@mozilla.com",
      "remixedFrom": null,
      "published": true
    },
    success: function(data, textStatus, jqXHR){
      console.log("Post resposne:");
      console.dir(data);
      console.log(textStatus);
      console.dir(jqXHR);
    },
    error: function(jqXHR, textStatus, errorThrown){
      console.log(jqXHR.responseText);
    }
  });

If you load http://localhost:5000/search, you can use the basic set of form fields to create/update/delete makes and search based on several fields.