Coder Social home page Coder Social logo

Comments (7)

asbjornu avatar asbjornu commented on June 27, 2024

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.

tpluscode avatar tpluscode commented on June 27, 2024

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.

asbjornu avatar asbjornu commented on June 27, 2024

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.

elf-pavlik avatar elf-pavlik commented on June 27, 2024

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.

alien-mcl avatar alien-mcl commented on June 27, 2024

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 the then). I'm not sure what's wrong with async/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.

elf-pavlik avatar elf-pavlik commented on June 27, 2024

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.

lanthaler avatar lanthaler commented on June 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.