The REST of the story

A coding renaissance took place a few years ago, Object-Oriented PHP, an application organization style called Model-View-Controller (MVC) and REST. MVC meant you had scripts for handling the database & data, the Model; scripts with templates to be filled in for pages, the View; and a script to listen to the URL, which ends with commands or function-names telling the application to do something, or the Controller.

It’s a great idea, it is not commonly used but it is not rare either. It yields nicely organized code which is urgently needed when you have applications with dozens of folders and hundreds of scripts.

REST is a library you add to your code, or is built into a framework like WordPress.. It lets you designate your own URLS and what actions to take when your app receives that URL. It looks like http://simili.io/simili/v1/get-brand. When I send that URL in a PHP script, or Javascript (it does both), it triggers a function I designated as well to return a JSON containing a logo, slogan, tagline and a closer. My PHP or Javascript unpacks that data, decoding it and then fills places in the Synopsis browser with that content. It is pretty sweet.

WordPress has a REST library, that is fairly easy to use. But the handbook for using it says we coders don’t have to use it and not to feel pressured to use it. It APOLOGIZES to us. And in all my years, I only had reason to use it now for the Simili website.

And this explains in a nutshell why REST is useful.

I mention how I preload all the data I need into my Javascript. This means you have to wait a short-time for it to load when you begin, but is super-quick afterward. It also means there is no need to bug the server for more. If I wanted to do that, I could ahve used AJAX. THe version of Javascript I code in, jQuery, has special commands to ping a server, and WordPress has a kind-of clunky way of setting up AJAX. I don’t need it though.

However, I found a reason to use REST. I decided to use it for my Logo, slogans, legalese, and to help me get anonymous demographic data from visitors.

All of these things are liable to change. And when I have 100k websites using my Simili Storyteller plugin, I don’t want to have 100k people update my plugin just because I have a new slogan.

Using REST, my corporate website, simili.io, can serve this content to the plugins. PHP and Javascript can both send special URLs to get this content and even upload things to a central repository. This puts 3 Server access technologies in order:

    When to use what technologies:

  • Preload data into Javascript to create an independent app that can be used if your computer is offline
  • Use AJAX if your Javascript needs to get data, save data or get the server to do stuff
  • Use REST to get content from an external place, like a corporate website if that content is liable to change, often

Posted

in

by

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

Upload Files Drag and drop your files here or click the button to upload your files from your computer

multi file upload Drag and drop your files Max Upload: 20 MB
close image preview
image preview
Task already exist for this element.
Write your message in the existing thread.
Here, we opened it for you.
Pushed to Media Folder.
The file was added to the website's media folder, you can now use it from the there.
poweredby
hide sidebar icon
sidebar left
sidebar menu
sidebar menuThis Page
sidebar menuAll Pages
sidebar menuShow Complete Tasks
sidebar menuShow Internal Tasks
sidebar menuSort by Date
sidebar menuSort by Priority
sidebar menuSort by Status
Tasks
Pages
no task in sidebar
Add your comments
Click any part of the page to start collaborating
              Loading...
              link to inbox
              responsive box
              desktop iconDesktop
              tablate iconTablet
              mobile iconMobile
              Browse Comment
              ×
              ×
              Approve Page

              When the page is ready, click the green button to signal to the webmaster that <b>this page is approved.

              there was some error. Please try again.
              ×
              Page Approved
              Desktop Tablet Mobile
              Back to Standard View
              You Ran Out of Website Slots

              That's great!
              It means you're growing & onboarding more clients!<br>Don't let it stop you

              There was some error. Please try again.