Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to expose REST service for JSON?

I need to expose a Spray service that accepts JSON payload. Where can I find a sample that would demonstrate such a feature?

like image 289
Giri Avatar asked Apr 11 '13 21:04

Giri


People also ask

How do I get JSON from a REST API endpoint?

To receive JSON from a REST API endpoint, you must send an HTTP GET request to the REST API server and provide an Accept: application/json request header. The Accept header tells the REST API server that the API client expects JSON.

Is JSON supported by RESTful services?

A RESTful web service usually defines a URI, Uniform Resource Identifier a service, provides resource representation such as JSON and set of HTTP Methods.

How do I read a JSON file in REST API?

First, the contents of the file should be converted to String. Then we should read the file content and convert it to Byte data type. Once the entire data is converted to Byte, we should finally convert it to string. We shall utilize an external JSON file as a payload for executing a POST request.


1 Answers

When I started learning Spray I used this awesome sample project. It shows you how to structure your application and much more.

If you want to have a look at how it uses spray-json at the route level, then take a look at this example.

Hope it helps! (kudos to Jacobus for S4)

like image 56
Arnaud Gourlay Avatar answered Sep 23 '22 00:09

Arnaud Gourlay