A
A
Anton Ivanov2015-04-07 12:28:00
JavaScript
Anton Ivanov, 2015-04-07 12:28:00

What tools to use to integrate with api on a separate domain via javascript?

Hello!

Given: There is a RESTful API on a separate domain. And there is a site where this API should be used.
I want to make communication with api organized via javascript, directly from the client browser.
That is, to create a user, let's say we do not submit the form, so that later there is a request from the server to the api, but immediately send a request to the api using javascript.

This scheme is new to me, so I ask for advice on how this is usually organized. Is there any recognized leader in javascript RESTful API clients? How do you usually organize the drawing of the result/next step? Let me explain, for example, after submitting the form, if successful, it is necessary to draw the second form, rather big. Is it normal, upon receiving a positive response from api, to make a request to your server to get the layout / template for the next step?
Well, what do you need to pay attention to?
I understand that everything can be written by hand, but why reinvent the wheel :)

Thanks in advance.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Kitmanov, 2015-04-07
@Fly3110

> Is there any recognized leader in javascript RESTful API clients?
All decent frameworks are REST-aware to some degree (Backbone/Angular/Ember).
> How is the drawing of the result/next step usually organized?
Received data -> updated model -> model kicked the view to re-render.
> Is it normal, upon receiving a positive response from api, to make a request to your server to get the layout / template for the next step?
It will be easier to load all the resources at once and then show the right one - less fuss with asynchrony. But if the volume is large, then it makes sense to ship as needed.
In order to go for data from another domain, the server with the API must be able to send CORS-headers, and the browser was able to ask them (that is, IE9- in flight). You can get around this with JSONP, as Dmitry rightly pointed out, but again, the server with the API must support JSONP.

D
Dmitry Tallmange, 2015-04-07
@p00h

To form queries, it is enough to have jquery:

$.ajax({
    url: 'http://example.com/',
    type: 'PUT',
    data: 'id=1&name=Valera',
    success: function() { console.log('PUT completed'); }
});

However, this will only work if the page being developed comes from the same domain.
If you are developing a page that loads from example.com and wants to make an ajax request to somehost.com , here is just JSONP.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question