Skip to content

crnk.io delivering json:api and plain data files

Notifications You must be signed in to change notification settings

scij/api-and-file

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Read Me

Purpose

This project demonstrates delivery of non-json resources in crnk.io.

The problem we had to solve was like this: a REST service with a JSON:API-Interface that manages and returns documents. The service was required to return either the document resource as JSON object or the raw document as PDF or other document formats.

We wanted to use the http accept header to choose between JSON:API and raw document data and we decided to use crnk.io.

The crnk.io documentation does not describe exactly how to do this and so I wrote this little example program to demonstrate how the problem can be solved with crnk.io.

Solution

The secret sauce is in the ext package. crnk.io detects modules on startup and initializes them. The BinaryResponseModule registers an instance of BinaryRequestProcessor which is derived from the JsonApiRequestProcessor and overrides the accepts method to check the http accept header but you could also check for resource names at this point.

The toHttpResponse method retrieves the document from the resource, sets the content type and returns the data stream.

About

crnk.io delivering json:api and plain data files

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages