• 1Get Started
  • 2Download Sample
  • 3Add Config Files
  • 4Include API Client
  • 5Deploy the Project
  • 6Add API Methods
  • 7It Works
  • 8You Made It!
We

Getting started with WeDeploy Data on the web

Add API Methods

Save Data

Now we want to add a script that will save data to a collection.

To do this, go to data-web-tutorial/ui/index.js and paste this code:

WeDeploy
  .data('db-.wedeploy.io')
  .create('tasks', {name: form.item.value })
  .then(function(response) {
    form.reset();
    form.item.focus();
    console.info('Saved:', response);
  })
  .catch(function(error) {
    console.error(error);
  });

Note: make sure to replace with the id of your project.

Fetch Data

Next, we want to add a script that will fetch data from the collection.

To do this, go to list.js inside of the same folder and paste this code:

WeDeploy
  .data('db-.wedeploy.io')
  .orderBy('id', 'desc')
  .limit(5)
  .get('tasks')
  .then(function(response) {
    appendTasks(response);
  })
  .catch(function(error) {
    console.error(error);
  });

Note: make sure to replace with the id of your project.

Pro Tip

In this tutorial we teach you how to use the .get() method which fetches the data from your collection everytime you refresh the page or make a new request. We also have a .watch() task which retrieves new data automatically when new data is created, giving you the power of real-time data!

Want to learn more about Real-Time Feeds?

Report a problemI added the API methods