deblockt / hal-rest-client

Typescript HAL Rest client
Apache License 2.0
25 stars 11 forks source link

Make restClient protected #5

Closed serhiivinichuk closed 7 years ago

serhiivinichuk commented 7 years ago

It would be useful to make HalResource.restClient field protected instead of private. This allows to create additional method in model classes that will make some requests or use the base url. For example, request for images or other non-HAL resources.

deblockt commented 7 years ago

What type of method do you want to use on restClient? I think that if you have an image associated to you entity, the image URL must be returned by Server, and mapped on entity property. Do you have a concrete example for your issue?

serhiivinichuk commented 7 years ago

Here are some examples that I would use in my project

  1. Resource has a link for an image that is dynamically generated.
    {
    "_links": {
    ...
    "preview": {
      "href": "resource/id/preview",
      "type": "image/*"
    },
    }
  2. Creating subresources.
    
    class SubResource extends HalResource { ... } 

class Resource extends HalResource { ... createSubResource(data) { this.restClient.create(url, data, SubResource) } }


I'm sure there're other ways it can be useful.
deblockt commented 7 years ago

I'm ok with the createSubResource method.

But, for your image issue, base Url is not accessible on restClient, it's not a property of HalRestClient. Can you use resource.uri instead? Or use a @HalProperty and get uri like this resource.preview.uri

serhiivinichuk commented 7 years ago

I figured out a way to deal with my images. Thank you. But having restClient for additional requests is still useful enhancement, in my opinion.

deblockt commented 7 years ago

I agree. It's done, you can upgrade to 0.2.3 version