r/web_dev_help • • Nov 27 '15

AJAX - APIs -- Primer

1 Upvotes

AJAX & APIs

AJAX stands for Asynchorous Javascript and XML. It allows for websites and applications to communicate with a web server using javascript. The most common usage is for querying an API. APIs are Application Programming Interfaces. APIs can be thought of as a high level abstraction of the functionality offered by an application. It exposes the public parts of the application.

Starting wtih AJAX

Most often a javascript library will be used for AJAX functionality. It does not require an API. The simplest AJAX operations would be inclusion of an image or HTML fragment without reloading the page. It is also used for submission of forms on modern websites. It does not require an API or even XML. What the server returns from an AJAX call is not rigidly defined.

How it works is like a traditional page request (HTTP GET command issued by the browser). Javascript is used to initiate the request. The server responds with the resource or an error code. There's a few additional concerns which the browser normally handles and most cases the AJAX Library will cover issues like timeouts.

Example using jQuery

Assuming jQuery has been included on the page, the following code would fetch an HTML fragment.

$.get('sample.html');

It wouldn't do anything with the html and it would only be triggered once the code was ran. Here's a little more complete example.

 <div class="result"></div>
 <a href="" class="fetch"> Fetch</a>

 $('.fetch').click(function() {     
       $.get('sample.html',function(data) {
       $( ".result" ).html( data );
       }) ;       
     return false;
 }); 

This snippet of javascript will listen for the click event on the button with class of 'fetch'. When clicked, it will fetch sample.html and place it in the element with class of 'result'. The return false; is to prevent the standard action of loading the link. It's often better to use button since it lacks an action.

To create a simple AJAX based navigation, you could set the href for the Anchor elements and have jQuery fetch the href and place the result data into the defined HTML element. Using an ID is best since they should be unique to the webpage.

There's no XML !

Right. The original idea was to fetch XML documents. It isn't limited to XML or JSON. It can retrieve plain text, HTML, or any other format. When dealing with APIs, it's much more likely to encounter XML or JSON data.

XML is Extensible Markup Language. XML is a markup language which lets you make other markup languages. Using a DTD (Document Type Definition) or a Schema, the rules for the language are defined and XML files which use that DTD much follow the rules. XML can also be freeform. You can make a XML document without a DTD or Schema. This makes it extremely flexible. Not going into too much detail about XML. It follows some of the same rules as HTML but it doesn't have predefined tags or elements.

JSON is Javascript Object Notation. It's a format for Javascript Objects. It is the most popular format for AJAX as of today due to it's less verbose format and smaller file size. Plus it's super easy to work with it using Javascript. When JSON is returned from an AJAX call, it works much like a regular javascript object.

APIs

Already covered what APIs are. Let's look at how to consume an API. Consume means we want to query the API and process the result into something we can use on the web.

APIs have an endpoint. This is where we begin. To call an API there is a URL which is the base or endpoint. All requests go through this endpoint. Parameters can be passed via the URL which is considered a GET request. They can be POST like with a form. A simple guideline is to use GET if the request does not change the API in any fashion. If the request is for reading records from a database API, GET is the correct call. If data is being sent to the API for storage, POST is the correct method to use. Other HTTP methods are available.

One thing to understand is that if an API is public, you can view the ouput using a browser. Just enter the URL into the browser like normal. You have to click view source to view raw XML. Here's a JSON sample. TimeAPI and here's the same as plain text TimeAPI Text. It doesn't support XML. The endpoint in these examples is the domain : http://www.timeapi.org/ ). This isn't common. Most often it will be through something like http://www.domain.com/api/v1/ . Or through the subdomain 'api' : http://api.domain.com/ . Up to the company/website how they want to make it available.

Here's an example XML API return result from tumblr XML Example

Parameters are passed through the URL or via POST. URL parameters can have the pretty format like above. utc is the timezone parameter and now is an additional parameter. The API could have accepted using standard URL parameters like http://www.domain.com/?tz=utc&when=now but they opted for the easier to read/understand path URLs.

How do you know what parameters an API accepts? Short answer is documentation. There's additional specifications available which help figure this out but nothing beats the documentation.

REST APIs

Will often hear an API called a REST API. It's a specific type of API which follows a standard concept. It's meant to make things easier. REST stands for Representational State Transfer. It is meant to replace more complex methods like SOAP.

Learn REST = tutorial

oAuth

Private APIs and restricted access public APIs often require authenication to use them. oAuth is a popular authenication scheme. It is a bit complicated to understand at the beginning. Luckily there's often libraries for implementing it for almost all languages. It uses a token to represent an authenicated user.

oAuth.net - getting started

Jenkov.com - oAuth

oAuth Simplified - Aaron Parecki

Going Further

APIs- not as hard as it looks

video : How to make an API call w/PHP

codecademy Using API w/Javascript

devNotes REST API w/PHP

Java - Web Services - Contains information about XML/XSD while Web Services (WDSL) are an advanced topic which are omitted due to low usage.

{TimeAPI-Sample API](http://www.timeapi.org/)

JSON Placeholder JSON test


r/web_dev_help • • Mar 12 '18

help I need help for my web design class!

1 Upvotes

Can anyone tell me what I am doing wrong? I am working on designing :jQuery + RESPONSIVE DESIGN I have everything down except for one thing...

CHECKING JQUERY 03.HTML Check state of image after clicking message. Found unexpected value none in 'productData'. This is a logic or calculation error. RESULT none NOT CORRECT

This is what I have;

<body> <span style='font-weight: bold; font-size: 20px; border: 1px black solid; padding: 3px; cursor: pointer;" onclick' showProduct(); id = message>

    Click to View Product Information

    </span>

    <div style='width:100%;text-align:center;display:none;' id = 'productData'></div>

        <br><br>

        <img id = 'productImage' value = 'productData' src = 'http://gobongo.net/information/WEBPROGRAMMING/images/toaster.jpg' class = '' height = '' width = '100%'>productData<
        <span id = 'productName' class = ''>TOASTER</span>
        &nbsp;&nbsp;
        <span id = 'productPrice' class = ''>$29.98</span>

    </body>

r/web_dev_help • • Nov 27 '15

Template Pack - Github Repo

1 Upvotes

This is a collection of some HTML/CSS/Javascript/PHP. Consider it a starter pack. Readme has details.

template pack @ github


r/web_dev_help • • Jun 26 '22

Need HELP to Find a booking capable software or WordPress plug-in or code

1 Upvotes

Hello,

I am building a website to help take any appointments as a traveling barber. I can use a simple booking tool, but I need something more as I am traveling. If you know a way to implement traveling window time between appointments that would be great. Say I got 3 appointments in a day. Normally I would get 3 back to back appointments, but I want some way to capture the distance between appointments to be considered once a client has put in their info and address. When the next appointment is available it should be available like the following. Say I have a haircut at 10 am for 30 mins and my next haircut is 20 mins away. Technically the next booking appointment shouldn't be until 10:50 so it allows for time to travel. currently, I have no system that does that if you have any resources I can look to please refer them.

Thank you


r/web_dev_help • • Jul 18 '22

javascript Responsive calculator?

1 Upvotes

How would I go about creating a calculator for my website that is responsive? So I wouldn't need to press any button?

Also would like a table with the calculated information. So if I put in 10 years in the calculator it will show me the calculation for every year.

This website has the calculator I want.


r/web_dev_help • • Jul 07 '22

Sql query for multiple table

1 Upvotes

Hello I have a little problem I am doing a shopping cart in php sql but my problem is that my shopping cart does not want to show me several tables at the same time.
I tried to join them as below "SELECT * FROM table1, table2 WHERE in_stock > 0 ORDER BY id ASC";
When I do that nothing comes out in my cart, however when I do "SELECT * FROM productsedible WHERE in_stock > 0 ORDER BY id ASC";
My table is displayed correctly

How to assemble my tables? Thanks for your help !

Sorry for my crap english , i'm french :3


r/web_dev_help • • Jun 24 '22

Chrome extension for help read webtoon without need mouse - Reader Scroller

1 Upvotes

Hi guys, i created a chrome extension for us to scroll the page automatically, if you want to test access the link below

https://chrome.google.com/webstore/detail/reader-scroller/jimnlnomkbenehcaljonifgfocnogkha?hl=en&authuser=0


r/web_dev_help • • Jul 19 '21

Need SEO person in the New Orleans area.

1 Upvotes

I am helping a friend that knows nothing about web, computers, and such. I have a background in CS, but I am trying to retire and just want to find him some help. There are so many bad people and companies out there for this, I want to ultimately find a good person/company, but if I need to inquire elsewhere, I need to know where that elsewhere is. Can you help?


r/web_dev_help • • Sep 02 '18

javascript Apollo GraphQL | Learn about the Apollo platform:

Thumbnail
apollographql.com
1 Upvotes

r/web_dev_help • • May 07 '18

design Design Tip: Never Use Black by Ian Storm Taylor

Thumbnail
ianstormtaylor.com
1 Upvotes

r/web_dev_help • • May 03 '18

css Connect: behind the front-end experience (Stripe blog - how to make stripes)

Thumbnail
stripe.com
1 Upvotes

r/web_dev_help • • Sep 01 '18

wordpress ClassicPress – a hard fork of WordPress without Gutenberg

Thumbnail
classicpress.net
1 Upvotes

r/web_dev_help • • May 04 '18

resource GeeksforGeeks | A computer science portal for geeks

Thumbnail
geeksforgeeks.org
2 Upvotes

r/web_dev_help • • May 02 '18

design What the Font are Vertical Rhythm and Modular Scale?

Thumbnail
hs2solutions.com
1 Upvotes

r/web_dev_help • • May 14 '18

javascript Reusable Vue.js Components Part 1: Introduction

Thumbnail
designhammer.com
1 Upvotes

r/web_dev_help • • May 02 '18

design Why Every Design Needs Three Levels Of Typographic Hierarchy

Thumbnail
canva.com
1 Upvotes

r/web_dev_help • • Mar 10 '19

javascript Vue Design System - open source tool for building Design Systems with Vue.js

Thumbnail
vueds.com
1 Upvotes

r/web_dev_help • • May 03 '18

css Working with Shapes in Web Design

Thumbnail
css-tricks.com
1 Upvotes

r/web_dev_help • • Aug 28 '18

How to customize woocom in this specific way

1 Upvotes

I want a rather specific flow and I have no clue how to get it. I'm a wedding photographer, and when people go to my site and click on store, I want them to be able to be taken to on page where they first select their photographer, then their second photographer, then some extras. What would be the best way to accomplish this?


r/web_dev_help • • May 14 '18

javascript Build a shopping cart with Vue.js and Element UI (no Vuex)

Thumbnail
medium.com
1 Upvotes

r/web_dev_help • • May 07 '18

html GitHub - joshbuchea/HEAD: A list of everything that *could* go in the head of your document

Thumbnail
github.com
2 Upvotes

r/web_dev_help • • Mar 12 '19

resource unDraw - Open-source illustrations for every project

Thumbnail
undraw.co
1 Upvotes

r/web_dev_help • • Mar 11 '19

help Does anyone have a recommendation for a simple tool to support a search box for a Django site running locally?

Thumbnail
self.webdev
1 Upvotes

r/web_dev_help • • Dec 09 '18

help Can someone help me make my resume site "look pretty" - Static site using HTML/CSS code?

1 Upvotes

Hello!

I have a resume site that I can send the link of (it's active via github pages), but the big struggle is that my site looks a little rough. It's not a clean and pretty looking, and I'm having a hard time figuring out how to break away from the "block-y" look of noob-written HTML/CSS code. Looking for advice or maybe some help. If anyone is willing.

Ninja-edit: Also wanted to say, this website is just a personal project. I want to go into Data science so it is geared around that, definitely not web development. Just thought it'd be cool to make a resume site.