Giter VIP home page Giter VIP logo

honeybear.halclient's Issues

HAL Forms

I see this lib will POST/PUT etc based on the href or a rel. Any plans to make it work with HAL-FORMS, a media type that returns meta data about required fields for POST/PUT verbs?

https://rwcbook.github.io/hal-forms/

NUnit 2.6.4 in VS2015

Hi, I have started a pull request to allow JsonPropertyAttributes on model classes ( #6 ) but I have problems to run the NUnit tests in Visual Studio 2015.
I can run it with NUnit outside of Visual Studio but some tests fail because the assembly binding redirect of Ploeh.SemanticComparison doesn't work.

I would like to add some tests for this new functionality.
Do you have an idea why it doesn't work?

Fill DTO Object with Elements from the resource and embedded Objects?

hello,
is it possible to retrive response data (in the example the "mainDTO") from the resource and embedded objects in one single call?

example:

using Newtonsoft.Json;
public class SubDTO{
    [JsonProperty("id")]
    public int ID { get; set; }
    [JsonProperty("name")]
    public string Name { get; set; }
}

using Newtonsoft.Json;
public class mainDTO{
    [JsonProperty("id")]
    public int ID { get; set; }
    [JsonProperty("name")]
    public string Name { get; set; }
    [JsonProperty("subDTOs")]
    public SubDTO[] SubDTOs { get; set; }
} 

json:

{
	"id": 12,
	"name": "my name",
	"_embedded": {
		"subDTOs": [{
			"id": 1,
			"name": "xyz"
		}, {
			"id": 1,
			"name": "xyz"
		}]
	}
}

Support for .NET 4.5

Hi,

I really like this fluent API. It'll be nice to have support for .NET 4.5 and above, instead only limited to 4.5.2.

Thanks.

Regards,

Roberto

Be able to specify which MediaTypeFormatter to use when PUT or POSTing

Hi!

I downloaded the latest version of the nuget package, and everything seems to work fine when fetching data from the API. But I'm still not able to specify the serializer settings when POSTing to the API.

In JsonHttpClient, these lines should also take in a MediaTypeFormatter:

public Task<HttpResponseMessage> PostAsync<T>(string uri, T value)
  => HttpClient.PostAsync(uri, value, _mediaTypeFormatter);

public Task<HttpResponseMessage> PutAsync<T>(string uri, T value)
  => HttpClient.PutAsync(uri, value, _mediaTypeFormatter);

I'm not sure what the best strategy is to use here. I see that you allow a collection of MediaTypeFormatters to be passed into the HalClient constructor. But we can only specify a single formatter when serializing objects. Should it instantiate the JsonHttpClient with the First() available MediaTypeFormatter?

Christian

Should accept application/hal+json as response content type

Hi, and thanks for a great HAL library.

Some APIs only return content with Content-Type: application/hal+json. Trying to consume these with HalClient fails, as this software only seems to accept application/json.

A fix for this would be to let the HalClient instantiation accept a System.Net.Http.Formatters.MediaTypeFormatter as a constructor parameter and use this for all serialization/deserialization for the current session.

I have some snippets that would allow for this, but would like to hear your thoughts on this before I proceed.

Retrieve single objects

Hi, i found your library and the api looks very nice for consuming hal based rest apis.

I have two questions regarding the api usage:

  1. Retrieve a single resource
    My Resource:
{
  "_embedded" : {
    "users" : [ {
      "id" : 2,
      "name" : "asddf",
      "_links" : {
        "self" : {
          "href" : "http://localhost:8080/users/2"
        },
        "user" : {
          "href" : "http://localhost:8080/users/2"
        },
        "address" : {
          "href" : "http://localhost:8080/users/2/address"
        }
      }
    } ]
  },
  "_links" : {
    "self" : {
      "href" : "http://localhost:8080/users{?page,size,sort}",
      "templated" : true
    },
    "profile" : {
      "href" : "http://localhost:8080/profile/users"
    }
  },
  "page" : {
    "size" : 20,
    "totalElements" : 1,
    "totalPages" : 1,
    "number" : 0
  }
}

How do i get the user resource with id 2 without fetching everything and traverse through the result? I am looking for a single http request solution to get /users/2 into my user dto.

  1. How is error handling solved?
    How do i check for all the http error codes and messages e.g.:
    /users/3 => 404 or with detailed json result.

Async support

Hi,

and thanks again for this great library, the fluent interface really is fun to use!

While using the first time I kind of expected the library to fully support async/await and was surprised it didn't. I figured this might be a nice excersice, so I went ahead trying to implement it.

Turns out going async and keeping the fluent interface wasn't straight-forward. The resulting pull-request (which I didn't send in yet, since it depends on #17) refactors quite a bit in the code, as such I understand you might hesitate merging or even question the approach taken.

Outlining it roughly:

  • HalClient is immutable, i.e. all the calls return a new copy with the new state
  • Most of the methods are extension methods operating on IHalClient, allowing easy chaining of Task<IHalClient>'s.

While the changes in the implementation are rather important, fortunately the tests behaved pretty nicely and only needed some slight changes, mainly for the immutable part. Also, adding tests for the async methods was as easy as copying the existing ones and only changing the sync method calls to the async method calls. Kudos!

You can find call the changes on this branch:
https://github.com/dmunch/HoneyBear.HalClient/tree/dmunch-async

If you decide to accept merging those changes there's a tiny list of things yet to be done. Of course I'd happily take care of these.

  • Add POST
  • Add PUT
  • Add PATCH
  • Add DELETE
  • Adjust documentation

Problem getting empty list from _embedded

Hi,
thanks for a really useful project.
I am still rather new at this so please consider that, it might be lack of understanding from my side. I have encountered one issue where I am not able to get an embeded object (see example below) if that object is empty (empty list). My understanding is that empty list is OK to be considered a "resource". Moreover, I cant handle this by catching the HoneyBear.HalClient.Models.FailedToResolveRelationship exception explicitly since that exception is "internal" - what is the reason to this design choice ? Any advice how this situation should be handled? Thanks in advance!
br
/Kazze

{ "_embedded": { "availableServices": [] }, "_links": { "self": { "href": "xx" } } }

How do I access nested Links?

Please help!

I cannot work out what I am supposed to do to get at nested Resources.

This code works
var allLocationLinks = halClient.Root().Get("visibleLocations").Item<AllLocations>().Data;
and returns 1000+ Locations with ID and Name but but I can't work out how to get at the Links to add the Advisers.

Cheers
Simon

Root JSON

{
  "_links": {
    "transactionMappingHierarchy": {
      "href": "https://XXX/nbs/transactionMappingHierarchy"
    },
    "accountByAccountNumber": {
      "href": "https://XXX/nbs/accounts/{accountNumber}",
      "templated": true
    },
    "accountByAccountId": {
      "href": "https://XXX/nbs/accounts/ids/{accountId}",
      "templated": true
    },
    "client": {
      "href": "https://XXX/nbs/clients/{clntId}",
      "templated": true
    },
    "visibleLocations": {
      "href": "https://XXX/nbs/locations"
    },
    "docs": {
      "href": "https://XXX/docs"
    }
  }
}

JSON from visibleLocations
{
  "locations": [
    {
      "locationId": 40000003,
      "name": "1000 IFA Firm 40000003 Ltd",
      "_links": {
        "self": {
          "href": "https://XXX/nbs/locations/40000003"
        },
        "advisers": {
          "href": "https://XXX/nbs/locations/40000003/advisers"
        }
      }
    },
    {
      "locationId": 100002441,
      "name": "10000 IFA Firm 100002441 Ltd",
      "_links": {
        "self": {
          "href": "https://XXX/nbs/locations/100002441"
        },
        "advisers": {
          "href": "https://XXX/nbs/locations/100002441/advisers"
        }
      }
    }, ...etc...

My POCO classes

	public class AllLocations
	{
		public Location[] Locations { get; set; }
	}

	public class Location
	{
		[JsonProperty("locationId")]
		public int ID { get; set; }

		public string Name { get; set; }

		[JsonProperty("advisers")]
		public Adviser[] Advisers { get; set; }
	}

	public class Adviser
	{
		[JsonProperty("adviserID")]
		public int ID { get; set; }

		public string Forename { get; set; }

		public string Surname { get; set; }

		[JsonProperty("adviserOutletID")]
		public int OutletID { get; set; }
	}

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.