- Notifications
You must be signed in to change notification settings - Fork7
fnproject/fn-jrestless-example
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Author:Rae Jeffries-Harris
This is an example JAX-RS app that can be deployed on the Fn platform.
JRestless allows you to create FaaS applications usingJAX-RS.We are addingsupport for using JRestless on Fn.
This means you can use all the JAX-RS features you're used to,@Path
,@GET
,@QueryParam
-all the marshalling and content-types, all the routing. All of it, in a FaaS function. JRestless usesJersey internally so you have the full capability of the reference JAX-RSimplementation.
If you take advantage ofFnProject's Hot Functionsyou can build a responsive application which only runs when it's needed.
This project is an example of how to use JRestless build a JAX-RS app on FnProject.
The code incom.example.fnjrestless.blog
is a JAX-RS app:
BloggingResource.java
- defines the routesBloggPost.java
- POJO domain objectBlogStore.java
- Database connection codeBloggingApp.java
- 5 lines of code to point JRestless at our app
Check out the code, then in the root of the project run:
$ fn build...snip...Function raej/jrest:0.0.4 built successfully.
Make sure you have an fn server running (Seethe tutorial - TL;DRfn start
)
Then create your app:
$ fn apps create jaxrsSuccessfully created app: jaxrs$ fn deploy --app jaxrs --local
You will need a database, easy way is to run the./start-mysql.sh
included in the repo.
Some config for your app:
## The IP address of the host from inside a container$export DOCKER_HOST_IP=$(docker inspect --type container -f'{{.NetworkSettings.Gateway}}' fnserver)fn apps configset jaxrs DB_URL"jdbc:mysql://${DOCKER_HOST_IP}/POSTS"fn apps configset jaxrs DB_DRIVER com.mysql.jdbc.Driverfn apps configset jaxrs DB_USER jaxrsfn apps configset jaxrs DB_PASSWORD SgRoV3s
Map the routes used by the app to the function:(use whichever image version was published in the previous deploy )
fn routes create jaxrs /route/html --image raej/jrest:0.0.2fn routes create jaxrs /route/blogs --image raej/jrest:0.0.2# fn routes create jaxrs /route/add <-- this was added by `fn deploy` earlier
All 3 of these routes will point to the same container image.
Browse tohttp://localhost:8080/r/jaxrs/route/html to see the blog's UI.
There is a simple HTML page served from/html
, which fetches data from/blogs
and posts new blog entries to/add
.
Fn treats each route independently, so there will beat least one per endpoint that you use. There may be more than one, as container instances will be created dynamically to cope with high load.
Fn currently does not support wildcards in routes. Issues#170 and#256 track current proposals to fix this.
About
Run JAX-RS applications on Fn using JRestless