0

I am trying spring-data-rest with mithril.js. However, I keep getting xml response from the repository instead of json.

I have this repository:

@RepositoryRestResource(collectionResourceRel = "people", path = "people")
public interface PersonRepository extends JpaRepository<Person, Long> {

And request with this:

var users = m.request({method: "GET", url: "/api/people/"});

However, I just got a list of string in xml response.

I tried to check the source as below, though I may mislook and point out the wrong source:

Found that mithril set the accept header as

xhr.setRequestHeader("Accept", "application/json, text/*")

mithril source: line 1079

However, it sounds spring-data-rest handle the request with

@ResponseBody
@SuppressWarnings({ "unchecked" })
@RequestMapping(value = BASE_MAPPING, method = RequestMethod.GET, produces = {
        "application/x-spring-data-compact+json", "text/uri-list" })
public Resources<?> getCollectionResourceCompact(RootResourceInformation repoRequest, DefaultedPageable pageable,

spring-data-rest source: line 171-173

instead of

@ResponseBody
@RequestMapping(value = BASE_MAPPING, method = RequestMethod.GET)
public Resources<?> getCollectionResource(final RootResourceInformation resourceInformation,

on spring-data-rest source: line 210-213

Is anything wrong on my ajax request?

  • Mithril's `m.request` is a _very_ lightweight AJAX wrapper — there are many situations where other AJAX utilities just work but Mithril somehow fails without deep customization of the XHR. Meanwhile in order to help with the Spring issue, it would be helpful to know what request headers Spring expects and what Mithril is actually sending… – Barney Jun 17 '15 at 07:52
  • Tried sending request from firefox, same problem. Doubt if mithril issue. Or, could you point out what wrong in the context mithril send? – chanueting Jun 17 '15 at 13:23

1 Answers1

0

Use curl to create the request and get that working the way you think it should. After that works, tackle the mithril part.

cgrinds
  • 21
  • 2
  • Tried sending request from firefox, same problem. Doubt if mithril issue. Or, could you point out what wrong in the context mithril send? – chanueting Jun 17 '15 at 13:28
  • Get it working in Firefox or curl first. That way you don't have to debug mithril and Spring at the same time. Once you have it working in curl, it should be straightforward to add the appropriate headers to mithril's request. – cgrinds Jun 17 '15 at 15:06