Comments (7)
As discussed in HydraCG/Specifications#138, a Promise
(i.e. callback) based way to handle responses would be nice, so we don't hard code the response expectation into the request side of the client code, but instead can handle that in a decoupled way in a more generalised response handler.
from heracles.ts.
Well, fetch is already promise-based so it's a natural pattern to follow with any deferred processing. I'd even use async/await...
And about processing itself, yes the client cannot assume what would be returned from an endpoint. That information must be determined only after receiving the bits.
from heracles.ts.
Well, fetch is already promise-based so it's a natural pattern to follow with any deferred processing. I'd even use async/await...
With async/await
, the coupling between the request and response has come full circle, I feel. That's why I originally suggested a callback approach, so that the response was explicitly decoupled from the request. With async/await
, the asynchronicity and decoupling is reduced to syntactic sugar with the very purpose of making it appear like synchronous code.
How do we reap the benefits of the event/callback approach being decoupled without using an event/callback approach, but Promises
that naturally leads to async/await
?
And about processing itself, yes the client cannot assume what would be returned from an endpoint. That information must be determined only after receiving the bits.
Exactly. I therefore find that getCollection()
is a bit too specific about the expected result.
from heracles.ts.
If we look at the current snippet with getCollection()
var operation = client.get("http://example.com")
.getApiDocumentation()
.getEntryPoint()
.getCollection({
property: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
object: "http://schema.org/Event"
})
.getOperationOfType('http://schema.org/CreateAction');
we can see that it does not take an IRI as parameter but ?s, p, o
pattern to match on the data present in the entry point.
{
"@context": "/api/context.jsonld",
"@id": "/api",
"@type": "hydra:EntryPoint",
"collection": {
"@id": "/api/events",
"title": "List of events",
"@type": "hydra:Collection",
"manages": [
{
"property": "rdf:type",
"object": "schema:Event"
}
],
"operation": [
{
"@type": ["hydra:Operation", "schema:CreateAction"],
"title": "Create new event",
"method": "POST",
"expects": "schema:Event"
}
]
}
}
Maybe name selectCollection()
would cause less confusion here, client could implement it as synchronous method on EntryPoint object.
function selectCollection (pattern) {
return this.collection.find(col => col.manages.includes(pattern))
}
from heracles.ts.
With async/await, the coupling between the request and response has come full circle, I feel. That's why I originally suggested a callback approach, so that the response was explicitly decoupled from the request.
As for JS,async
/await
is only syntactic sugar on top of promises, which are somehow callback-driven (function passed to thethen
). I'm not sure what's wrong withasync
/await
. That coupling is only a feeling - it's still non-blocking, lazy resolved operation.
we can see that it does not take an IRI as parameter but ?s, p, o pattern to match on the data present in the entry point.
Oh, that's the worst - way to RDF'ish. We can go that way if we want to scare developers off.
Exactly. I therefore find that getCollection() is a bit too specific about the expected result.
I agree
from heracles.ts.
we can see that it does not take an IRI as parameter but ?s, p, o pattern to match on the data present in the entry point.
Oh, that's the worst - way to RDF'ish. We can go that way if we want to scare developers off.
I would see it appropriate for the client to besides generic selectCollection()
which takes triple pattern, also provide more specific selectCollectionByMembersType()
which would simply take IRI (or CURIE once we clarify how to manage JSON-LD context used by cilent). I consider it a much cleaner approach than trying to add some more specific handling of manages
with rdf:type
to the vocabulary itself.
function selectCollectionByMembersType (membersType) {
return this.selectCollection({
property: "http://www.w3.org/1999/02/22-rdf-syntax-ns#type",
object: membersType
}))
}
To get back on my point about selectCollection()
, it wouldn't actually fetch the resource but only acts as helper on EntryPoint. Implementation could stay synchronous so I don't see it directly related to this issue.
from heracles.ts.
I filed a separate issue for the collection selection discussion. Let's keep this issue focus on the lazy processing aspect. Please also keep in mind that lazy processing is not about asynchronous network requests. If we need discussions for that too, please file a separate one.
from heracles.ts.
Related Issues (20)
- Not able to use Heracles.ts in my Project. HOT 5
- Consider renaming displayName to title HOT 1
- Get class property value HOT 2
- Question on status of spec and releases HOT 3
- Dependency Dashboard
- Don't mint blank node IDs unless absolutely necessary HOT 2
- Revisit extraction of "hypermedia" from resources HOT 1
- Extending from Arrays (Compatibility) HOT 3
- Apidocumentation instance set entrypoint property as undefined HOT 5
- Improve operation invocation API with IRI templates
- Obtaining whole collection HOT 1
- Are responses fully typed? HOT 7
- Document how to install and use Heracles.ts HOT 2
- correctly using heracles on a localhost HOT 6
- Links are to strict HOT 1
- Hypermedia lacks response headers HOT 1
- Consider compensation for missing entry point in API documentation HOT 1
- Cease support for memberTemplate HOT 1
- Add support for other RDF serializations
- Multiple API documentations
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from heracles.ts.