I am new to RAML and I have a basic question:
It is not possible to specify a set of alternative baseUri (only a single is allowed). Is there any alternative way to model multiple alternative installations of an API (e.g. for separate release-cycle environments)?
One way could be to use baseUriParameters and using an enum value for the different deployments.
#%RAML 0.8
title: Some Service
version: 1
baseUri: https://{environment}/rest/v{version}/services/someservice
baseUriParameters:
environment:
description: Integration test, Acceptance Integration Test, Production
enum: ["test-api.company.com","acc-api.company.com","api.company.com"]
The way I deal with this is by templating baseUri.
For JVM apps I use:
baseUri: ${baseUri}
and render the RAML file as a JSP.
For Ruby apps I use:
baseUri: <%= base_uri >
and render as ERB.
The value for baseUri is computed on the fly, based on the inbound request, so it's always matching the host / domain where it's deployed.
Related
I' building a small website. The back-end is written in Kotlin and uses Spring boot, and the front-end is built in Elm.
The generated javascript app will be served statically by my back-end on deployment.
For development, I currently work as such :
Serve my spring boot application on localhost:8080
Serve my Elm app on b using create-elm-app
The main reason is that create-elm-app allows for hot-compilation and hot-reload of the Elm app, which makes it very convenient.
The problem with this is that I have to set up all my elm http calls against another port locally, which means I have to alter the code for production.
Ideally, I'd like to:
Either have live-recompilation of elm code that changes ( I used chokidar in node, but didn't find a direct java alternative) coupled to a spring boot hot reload
Have create-elm-app redirect my API calls
Or auto-proxy all my calls to another location via a third party
Does anyone have experience with this? What setup would you recommend?
Cheers,
Alright, using the word proxy did help!
It seems that the create-elm-app documentation already expects this use case. You can read more about it here.
Basically what needs to be done is:
Create a elmapp.config.js file at the root of the elm project, with the following content (in my case, you can adapt):
module.exports = {
proxy: "http://localhost:8080",
}
Then, in your elm code, use absolute URLs. For example :
makeCreateGameUrl : Model -> String
makeCreateGameUrl model =
absolute
[ "game" ]
[ string "players" (joinListOfStrings model.newPlayerNames) ]
After this, your API calls will be directly redirected to your backend.
I have a rest service which returns a json response. I need to validate response against my predefined json schema using groovy script. All the options I have found on the net describe validating json response using groovy.json.JsonSlurper against some pre conditions not the schema. So I am kinda confused where to start from. But I roughly know that I need the following steps get done.
Define custom json schema
Importing some json validator library
And validate response against schema in groovy
I'd be highly grateful if anybody helps out on the steps 2 and 3.
For your notice, I am using Soap ui tool and here is my custom schema:
{
"$schema": "http://json-schema.org/schema#",
"type":"array",
"items":{
"type": "string"
}
}
Loading libraries in Groovy depends on the tool. In SoapUI-5.6.0 the standard way is to put jar files in (from SoapUI base installation path):
On Mac: bin/ext
On Linux & Windows: lib
Validation differs depending on the library. For example with groovy-json-schema:
def json = new JsonSlurper().parseText('{"an": "example"}')
use(JsonSchema) {
json.schema = 'file://path/to/your/json/schema.json'
json.conformsSchema()
}
I built an api only rails app, but since i'm using a 3rd party email service, I need to be able to render the email template into a string to pass it to the mailing service wrapper gem. So far any attempt to render templates into a string returns an empty string, and i suspect it is because the application is configured to be API only. Ho do I add support to rendering templates into a string?
If this is not the case, please let me know. I'm using postmark mail service. postmark-rails gem, which integrates into standard rails mailers didn't work at all, and plain postmark gem (which uses postmark API instead of postmark SMTP server) works fine, but now my problem is producing the proper html for the email.
this is what I'm trying:
html = render_to_string(
partial: "transfer_mailer/transfer.html.erb",
locals: {
:#body => #body,
:#campaign => #campaign,
:#chat => #chat
}
)
but it returns empty string.
My setup involves Rails 5.0.1, ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux], Sidekiq 4.2.7, and in production im using nginx/1.10.2 and Phusion Passenger 5.1.1. Production environment is deployed in an azure virtual machine, and I added both inbound and outbound rules for allowing traffic through ports 25, 465, 2525, and 587.
Any help would be really appreciated.
Looking at the docs for render_to_string, it looks like the path doesn't need to include .html.erb, so maybe removing that will fix it.
You can see here for some example code:
In your case, it would be:
render_to_string(
partial: '/transfer_mailer/transfer',
locals: {
:#body => #body,
:#campaign => #campaign,
:#chat => #chat
},
layout: false
)
Also make sure the partial filename starts with an underscore, even though you don't include it with render_to_string or render calls.
There is the other way to use render_to_string for resolving your issue. Please see the code below.
#body = XXX
#campaign = YYY
#chat = ZZZ
html = render_to_string(
file: 'transfer_mailer/transfer.html.erb'
)
Hope it helps.
I have a Web API OData project and everything is working great. I'm now trying to return xml instead of JSON using the $format parameter, as opposed to specifying a header request, and it is not working. I've tried these approaches:
http://localhost:3845/api/Customer?$format=application/xml
http://localhost:3845/api/Customer?$format=xml
http://localhost:3845/api/Customer?$format=application/xml;odata.metadata=full
All without success. This article says that it is possible: https://blogs.msdn.microsoft.com/webdev/2014/03/13/getting-started-with-asp-net-web-api-2-2-for-odata-v4-0/
I have updated all of my NuGet packages, but it seems that the request is always ignored, and instead I get JSON every time.
Since the ATOM format (XML) is only a technical committee specification instead of an OASIS standard for the OData V4 protocol, the ATOM format is disabled in the ODataLib from the version 6.3.0.
The correct way to ask the OData V4 service to respond in XML is as follows:
GET http://localhost:3845/api/Customer?$format=application/atom+xml
or set the header Accept to application/atom+xml. But due to the reason mentioned above, it doesn't work for Web API OData V4.
To support $format=xml and $format=json, add the following configuration:
config.Formatters.JsonFormatter.AddQueryStringMapping("$format", "json", "application/json");
config.Formatters.XmlFormatter.AddQueryStringMapping("$format", "xml", "application/xml");
I am trying to localize Lenya publication URLs.
I store URL translation in the Document metadata and rewrite urls with URLRewriter transformator.
e.g. I build
/lenya/default/authoring/en/home
from
/lenya/default/authoring/index.html
But I can't find a simple way to force Lenya to tranlate incoming request URI back to the original path: /lenya/default/authoring/index.html
Really I want to process the request via pipelines using the original URL, not translated.
Is it possible at all? I had tried to add a servlet filter and use dispatcher, but filter can't access documents metadata because Environment object isn't in the processing stack yet at this stage...
(At this moment I see only one way - to update CocoonServlet and Cocoon classes)
Thanks!
I was able to do this via a RequestListener.
In the public void onRequestStart(Environment environment) method I create RequestWrapper with a new real URL and put it into objectModel. Also I change Environment context with a real URL: env.setContext("", realUrl, env.getContext())
This works fine!