New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: JSON-only endpoints with client/server side collaboration #8323

Closed
mrclay opened this Issue May 18, 2015 · 8 comments

Comments

Projects
None yet
2 participants
@mrclay
Member

mrclay commented May 18, 2015

(90% of this is done, but I figure it would be best to stop and get input here)

Server side

Create an endpoint via elgg()->jsonEndpoints->register($name, $handler). ($handler can be a class name if it's invokable).

On a request for that endpoint, the $handler receives a single Api object with properties:

  • elgg: the Elgg\Application object
  • ttl: (int) How long the client can cache the response, default: 0

If the handler returns a symfony Response object, we set the expires (if non-zero) and send() it.

Otherwise, we pass the return value through a [jsonResponse, $endpoint_name] hook (for plugin collaboration), wrap the value to encapsulate system messages, and turn it into a JsonResponse.

Client side

An AMD module provides a class Endpoint(name) with methods to fetch a value and load it into a jQuery-wrapped $target, both automatically using elgg/spinner by default.

Before you receive the data, the system messages container is processed and removed, and the data is filtered through the client hook [jsonResponse, $endpoint_name]. We could have an Endpoint method listen to simplify registering listeners created by other plugins.

To simplify, there are no URL segments, just a data object sent in the fetch options which is accessed via ->input server-side (query string/POST body).

While fetching, you can set data.response_ttl to preset the TTL of the response. I've found this quite useful in the past.

@mrclay

This comment has been minimized.

Show comment
Hide comment
@mrclay

mrclay May 18, 2015

Member

Goal is to make it quick/easy to define and use endpoints without the gotchas/magic of our ajax views and actions. If you wanna render views/forms/whatever, that's your business.

Member

mrclay commented May 18, 2015

Goal is to make it quick/easy to define and use endpoints without the gotchas/magic of our ajax views and actions. If you wanna render views/forms/whatever, that's your business.

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue May 19, 2015

@ewinslow

This comment has been minimized.

Show comment
Hide comment
@ewinslow

ewinslow May 23, 2015

Member

Can you write up some more complete docs with code samples that focus first on the developer experience? You've explained a lot here and after reading the code and your description twice I think I've got it, but some code samples would probably help I think...

Member

ewinslow commented May 23, 2015

Can you write up some more complete docs with code samples that focus first on the developer experience? You've explained a lot here and after reading the code and your description twice I think I've got it, but some code samples would probably help I think...

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue May 26, 2015

@mrclay

This comment has been minimized.

Show comment
Hide comment
@mrclay

mrclay May 27, 2015

Member

#8373 (comment) there's a use case for allowing the response to send the client a list of resources to load/require(). Limitation being these would be handled implicitly before the caller got a chance to use the returned markup. E.g. an initializer module returned might scan the DOM before the returned HTML is placed in it. But still definitely useful.

Member

mrclay commented May 27, 2015

#8373 (comment) there's a use case for allowing the response to send the client a list of resources to load/require(). Limitation being these would be handled implicitly before the caller got a chance to use the returned markup. E.g. an initializer module returned might scan the DOM before the returned HTML is placed in it. But still definitely useful.

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue May 29, 2015

@mrclay

This comment has been minimized.

Show comment
Hide comment
@mrclay
Member

mrclay commented May 29, 2015

WIP #8391

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue May 31, 2015

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue May 31, 2015

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue Jun 1, 2015

feature(ajax): Adds a new elgg/ajax module with unified API
Unlike the 1.8 API, all methods transparently handle server-side messages
and errors, and return the raw value without exposing the JSON wrapper.
A client plugin hook allows modifying the request data, and both client
and server-side hooks can modify the returned value.

Fixes #8323

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue Jun 1, 2015

feature(ajax): Adds a new elgg/ajax module with unified API
Unlike the 1.8 API, all methods transparently handle server-side messages
and errors, and return the raw value without exposing the JSON wrapper.
A client plugin hook allows modifying the request data, and both client
and server-side hooks can modify the returned value.

Fixes #8323
Conflicts:
	engine/classes/Elgg/Di/ServiceProvider.php
@mrclay

This comment has been minimized.

Show comment
Hide comment
@mrclay

mrclay Jun 2, 2015

Member

Better: #8402

Member

mrclay commented Jun 2, 2015

Better: #8402

@mrclay

This comment has been minimized.

Show comment
Hide comment
@mrclay

mrclay Jun 2, 2015

Member

Note the goal of this ticket has shifted away from creating new endpoints and is now to add the richer Ajax experience to all the existing request handlers in a BC way.

Member

mrclay commented Jun 2, 2015

Note the goal of this ticket has shifted away from creating new endpoints and is now to add the richer Ajax experience to all the existing request handlers in a BC way.

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue Jun 4, 2015

feature(ajax): Adds a new elgg/ajax module with unified API
All elgg/ajax methods transparently handle server-side messages/errors, as
well as return the raw value (the JSON wrapper is not exposed to the user
as in elgg.action().)

A client plugin hook allows modifying the request data, and both client
and server-side hooks can modify the returned value.

Fixes #8323

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue Jun 9, 2015

feature(ajax): Adds a new elgg/ajax module with unified API
All elgg/ajax methods transparently handle server-side messages/errors, as
well as return the raw value (the JSON wrapper is not exposed to the user
as in elgg.action().)

A client plugin hook allows modifying the request data, and both client
and server-side hooks can modify the returned value.

Fixes #8323
@mrclay

This comment has been minimized.

Show comment
Hide comment
@mrclay

mrclay Jun 21, 2015

Member

#8402 is the way to go.

Member

mrclay commented Jun 21, 2015

#8402 is the way to go.

@mrclay mrclay closed this Jun 21, 2015

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue Sep 17, 2015

feature(ajax): Adds a new elgg/ajax module with unified API
All elgg/ajax methods transparently handle server-side messages/errors, as
well as return the raw value (the JSON wrapper is not exposed to the user
as in elgg.action().)

A client plugin hook allows modifying the request data, and both client
and server-side hooks can modify the returned value.

Fixes #8323
@mrclay

This comment has been minimized.

Show comment
Hide comment
@mrclay

mrclay Sep 17, 2015

Member

#8955 is updated for 2.x

Member

mrclay commented Sep 17, 2015

#8955 is updated for 2.x

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue Sep 18, 2015

feature(ajax): Adds a new elgg/ajax AMD module with unified API
All elgg/ajax methods transparently handle server-side messages/errors, as
well as return the raw value (the JSON wrapper is not exposed to the user
as in elgg.action().)

A client plugin hook allows modifying the request data, and both client
and server-side hooks can modify the returned data.

Fixes #8323

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue Sep 18, 2015

feature(ajax): Adds a new elgg/ajax AMD module with unified API
All elgg/ajax methods transparently handle server-side messages/errors, as
well as return the raw value (the JSON wrapper is not exposed to the user
as in elgg.action().)

A client plugin hook allows modifying the request data, and both client
and server-side hooks can modify the returned data.

Fixes #8323

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue Sep 18, 2015

feature(ajax): Adds a new elgg/ajax AMD module with unified API
All elgg/ajax methods transparently handle server-side messages/errors, as
well as return the raw value (the JSON wrapper is not exposed to the user
as in elgg.action().)

A client plugin hook allows modifying the request data, and both client
and server-side hooks can modify the returned data.

Fixes #8323

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue Sep 18, 2015

feature(ajax): Adds a new elgg/ajax AMD module with unified API
All elgg/ajax methods transparently handle server-side messages/errors, as
well as return the raw value (the JSON wrapper is not exposed to the user
as in elgg.action().)

A client plugin hook allows modifying the request data, and both client
and server-side hooks can modify the returned data.

Fixes #8323

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue Sep 20, 2015

feature(ajax): Adds a new elgg/Ajax AMD module with unified API
All elgg/Ajax methods transparently handle server-side messages/errors, as
well as return the raw value (the JSON wrapper is not exposed to the user
as in elgg.action().)

A client plugin hook allows modifying the request data, and both client
and server-side hooks can modify the returned data.

Fixes #8323

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue Sep 30, 2015

feature(ajax): Adds a new elgg/Ajax AMD module with unified API
All elgg/Ajax methods transparently handle server-side messages/errors, as
well as return the raw value (the JSON wrapper is not exposed to the user
as in elgg.action().)

A client plugin hook allows modifying the request data, and both client
and server-side hooks can modify the returned data.

Fixes #8323

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue Dec 7, 2015

feature(ajax): Adds a new elgg/Ajax AMD module with unified API
All `elgg/Ajax` methods transparently handle server-side messages/errors, as
well as return the raw value (the JSON wrapper is not exposed to the user
as in `elgg.action()`.)

A client plugin hook allows modifying the request data, and both client
and server-side hooks can modify the returned data.

You can test this by enabling the developers plugin and entering this at the
JavaScript console: `require(["developers/ajax_demo"])`

The ajax views system can now serve static views that weren't specifically
registered for ajax. This is mainly for fetching static `.html` view files.

Fixes #8323

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue Dec 7, 2015

feature(ajax): Adds a new elgg/Ajax AMD module with unified API
All `elgg/Ajax` methods transparently handle server-side messages/errors, as
well as return the raw value (the JSON wrapper is not exposed to the user
as in `elgg.action()`.)

A client plugin hook allows modifying the request data, and both client
and server-side hooks can modify the returned data.

You can test this by enabling the developers plugin and entering this at the
JavaScript console: `require(["developers/ajax_demo"])`

The ajax views system can now serve static views that weren't specifically
registered for ajax. This is mainly for fetching static `.html` view files.

Fixes #8323

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue Dec 7, 2015

feature(ajax): Adds a new elgg/Ajax AMD module with unified API
All `elgg/Ajax` methods transparently handle server-side messages/errors, as
well as return the raw value (the JSON wrapper is not exposed to the user
as in `elgg.action()`.)

A client plugin hook allows modifying the request data, and both client
and server-side hooks can modify the returned data.

You can test this by enabling the developers plugin and entering this at the
JavaScript console: `require(["developers/ajax_demo"])`

The ajax views system can now serve static views that weren't specifically
registered for ajax. This is mainly for fetching static `.html` view files.

Fixes #8323

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue Dec 8, 2015

feature(ajax): Adds a new elgg/Ajax AMD module with unified API
All `elgg/Ajax` methods transparently handle server-side messages/errors, as
well as return the raw value (the JSON wrapper is not exposed to the user
as in `elgg.action()`.)

A client plugin hook allows modifying the request data, and both client
and server-side hooks can modify the returned data.

You can test this by enabling the developers plugin and entering this at the
JavaScript console: `require(["developers/ajax_demo"])`

The ajax views system can now serve static views that weren't specifically
registered for ajax. This is mainly for fetching static `.html` view files.

Fixes #8323

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue Dec 8, 2015

feature(ajax): Adds a new elgg/Ajax AMD module with unified API
All `elgg/Ajax` methods transparently handle server-side messages/errors, as
well as return the raw value (the JSON wrapper is not exposed to the user
as in `elgg.action()`.)

A client plugin hook allows modifying the request data, and both client
and server-side hooks can modify the returned data.

You can test this by enabling the developers plugin and entering this at the
JavaScript console: `require(["developers/ajax_demo"])`

The ajax views system can now serve static views that weren't specifically
registered for ajax. This is mainly for fetching static `.html` view files.

Fixes #8323

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue Dec 8, 2015

feature(ajax): Adds a new elgg/Ajax AMD module with unified API
All `elgg/Ajax` methods transparently handle server-side messages/errors, as
well as return the raw value (the JSON wrapper is not exposed to the user
as in `elgg.action()`.)

A client plugin hook allows modifying the request data, and both client
and server-side hooks can modify the returned data.

You can test this by enabling the developers plugin and entering this at the
JavaScript console: `require(["developers/ajax_demo"])`

The ajax views system can now serve static views that weren't specifically
registered for ajax. This is mainly for fetching static `.html` view files.

Fixes #8323

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue Dec 8, 2015

feature(ajax): Adds a new elgg/Ajax AMD module with unified API
All `elgg/Ajax` methods transparently handle server-side messages/errors, as
well as return the raw value (the JSON wrapper is not exposed to the user
as in `elgg.action()`.)

A client plugin hook allows modifying the request data, and both client
and server-side hooks can modify the returned data.

You can test this by enabling the developers plugin and entering this at the
JavaScript console: `require(["developers/ajax_demo"])`

The ajax views system can now serve static views that weren't specifically
registered for ajax. This is mainly for fetching static `.html` view files.

Fixes #8323

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue Dec 26, 2015

feature(ajax): Adds a new elgg/Ajax AMD module with unified API
All `elgg/Ajax` methods transparently handle server-side messages/errors, as
well as return the raw value (the JSON wrapper is not exposed to the user
as in `elgg.action()`.)

A client plugin hook allows modifying the request data, and both client
and server-side hooks can modify the returned data.

You can test this by enabling the developers plugin and entering this at the
JavaScript console: `require(["developers/ajax_demo"])`

The ajax views system can now serve static views that weren't specifically
registered for ajax. This is mainly for fetching static `.html` view files.

Fixes #8323

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue Dec 26, 2015

feature(ajax): Adds a new elgg/Ajax AMD module with unified API
All `elgg/Ajax` methods transparently handle server-side messages/errors, as
well as return the raw value (the JSON wrapper is not exposed to the user
as in `elgg.action()`.)

A client plugin hook allows modifying the request data, and both client
and server-side hooks can modify the returned data.

You can test this by enabling the developers plugin and entering this at the
JavaScript console: `require(["developers/ajax_demo"])`

The ajax views system can now serve static views that weren't specifically
registered for ajax. This is mainly for fetching static `.html` view files.

Fixes #8323

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue Dec 26, 2015

feature(ajax): Adds a new elgg/Ajax AMD module with unified API
All `elgg/Ajax` methods transparently handle server-side messages/errors, as
well as return the raw value (the JSON wrapper is not exposed to the user
as in `elgg.action()`.)

A client plugin hook allows modifying the request data, and both client
and server-side hooks can modify the returned data.

You can test this by enabling the developers plugin and entering this at the
JavaScript console: `require(["developers/ajax_demo"])`

The ajax views system can now serve static views that weren't specifically
registered for ajax. This is mainly for fetching static `.html` view files.

Fixes #8323

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue Dec 26, 2015

feature(ajax): Adds a new elgg/Ajax AMD module with unified API
All `elgg/Ajax` methods transparently handle server-side messages/errors, as
well as return the raw value (the JSON wrapper is not exposed to the user
as in `elgg.action()`.)

A client plugin hook allows modifying the request data, and both client
and server-side hooks can modify the returned data.

You can test this by enabling the developers plugin and entering this at the
JavaScript console: `require(["developers/ajax_demo"])`

The ajax views system can now serve static views that weren't specifically
registered for ajax. This is mainly for fetching static `.html` view files.

Fixes #8323

mrclay added a commit to mrclay/Elgg-leaf that referenced this issue Dec 26, 2015

feature(ajax): Adds a new elgg/Ajax AMD module with unified API
All `elgg/Ajax` methods transparently handle server-side messages/errors, as
well as return the raw value (the JSON wrapper is not exposed to the user
as in `elgg.action()`.)

A client plugin hook allows modifying the request data, and both client
and server-side hooks can modify the returned data.

You can test this by enabling the developers plugin and entering this at the
JavaScript console: `require(["developers/ajax_demo"])`

The ajax views system can now serve static views that weren't specifically
registered for ajax. This is mainly for fetching static `.html` view files.

Fixes #8323
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment