deblockt / hal-rest-client

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

resource.create() in version 0.3.0 differs from 0.2.6 #15

Closed baxtheman closed 5 years ago

baxtheman commented 7 years ago

Hi,

I've upgrade to last version 0.3.0 and the resource.create() gets error from the java spring data backend.

Code to save new resource:

const resource = createResource(halData, HalResource, '/rilevazione');

resource.prop('data', date);
resource.prop('commessa', order.links.commessa.uri);

resource.create()

the json POST by browser to backend, version 0.2.6

{
    "commessa": "http://95.242.194.83:8080/test-api-v3/data/commessa/1641",
    "data": "2017-10-02T22:00:00.000Z",
    ...
}

the json POST by browser to backend, version 0.3.0

{
    "commessa": {
        "fetchedURI": "",
        "templated": false,
        "uri": "http://localhost:8180/registrazioni/data/commessa/1630"
    },
    "data": "2017-10-02T22:00:00.000Z",
    ...
}

The last version is not recognized by the backend and it produces an exception (commessa field empty).

What can I do to resolve? thx

deblockt commented 7 years ago

Hello,

You must use "order.links.commessa.uri.uri" insteadof "order.links.commessa.uri". Now URI is an object, refer to https://github.com/deblockt/hal-rest-client#from-02

I think, i will add a parser for automaticly transform URI to String

deblockt commented 7 years ago

You can also write something like this :

resource.prop('commessa', new HalResource(client, order.links.commessa));