简体   繁体   中英

Spring MongoDB REST API without HAL?

This Guide shows how to easily create a RESTful interface to a Mongo Database. It produces Json-data in HAL format(Hypertext Application Language), but unfortunately I am unable to find a working Android Client that supports HAL.

Is there any way to disable this HAL format an just GET the documents from the DB without any extra? So that it can be directly parsed into my datatype classes?

It would be really nice to use this approach to somehow automatically generate the REST interface, I cannot go back to manually writing all the methods in controllers after seeing this very short code.

This post seems to deal with the same topic, but I do not understand how to do this configuration.

The guide you are linking to is specifically aimed at using Spring Data REST + Spring Data MongoDB, so to disable the hypermedia for a project designed to generate hypermedia, ie a RESTful interface, sounds very strange.

On a mobile platform like Android, the question is what are you trying to do? Are you trying to query for a single, small piece of JSON from MongoDB? The risk of not having any type of hypermedia layer in the middle is that you could query for a giant (ie humongous data set) and cripple both the server and mobile device.

For more details about hypermedia and Spring Data REST, check out Oliver Gierke's answer at Disable Hypertext Application Language (HAL) in JSON? .

Regarding the ability to communicate between Android and a HAL backend, of course it's possible. You may wish to look at Roy Clarkson's sample Android app used to talk to a HAL backend that was used at SpringOne 2014 at https://github.com/SpringOne2GX-2014/spring-a-gram-android .

The slides from that presentations are at https://speakerdeck.com/gregturn/springone2gx-2014-spring-data-rest-data-meets-hypermedia .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM