A new idea when I'm writing #14952 , it is a proposal to try creating a Joomla.Http
object to make our frontend programming more modern.
I dont't think it is necessary for Joomla CMS now since our controller didn't handle PUT and DELETE methods, but I still note a new idea here to consider maybe some developers may need this to call 3rd party APIs.
Use sendRequest()
as main entry, it is similar to HttpPlug's HttpClient
interface
Joomla.Http.sendRequest('GET', url, data, headers, options);
// Or use object options
Joomla.Http.sendRequest(requestOptions);
Should return a Promise
object.
Joomla.Http.sendRequest(...).then(res => console.log(res.body));
For IE8, we can simply include a
promise-polyfill.js
or adapt jQuery.Deferred to Promise A/+ like this
Simple shortcuts
Joomla.Http.get(url, headers, options).then();
Joomla.Http.post(url, data, headers, options).then();
Joomla.Http.put(url, data, headers, options).then();
Joomla.Http.delete(url, data, headers, options).then();
Joomla.Http.head(url, data, headers, options).then();
Support auto inject the CSRF token:
Joomla.Http.defaultOptions.headers.post['X-CSRF-Token'] = token;
These are not required but also list here.
Maybe support X-HTTP-Method-Override
or _method=PUT
query:
Joomla.Http.sendRequest({ emulateHTTP: true });
Or application/x-www-form-urlencoded
Joomla.Http.sendRequest({ emulateJSON: true });
By default, Joomla.Http should send all request as
application/x-www-form-urlencoded
because it is similar tojQuery.ajax()
and we don't need to change the backend code.
Another suggestion is that we can consider simply wrap axios or just include it in as js vendor since it is popular in frontend developers.
Labels |
Added:
?
|
Status | New | ⇒ | Discussion |
Category | ⇒ | Front End |
Status | Discussion | ⇒ | New |
Status | New | ⇒ | Information Required |
@mbabker any Statement?
@mbabker can Maintainer make a Decision on this?
Status | Information Required | ⇒ | Needs Review |
Status is set on "Needs Review".
Status | Needs Review | ⇒ | Closed |
Closed_Date | 0000-00-00 00:00:00 | ⇒ | 2018-07-24 15:30:04 |
Closed_By | ⇒ | brianteeman |
Opinion of @production Department?
This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/14994.