Is there any way to share a resolver response template with other resolvers in AWS appsync - aws-appsync

I am trying to add some common response headers to the resolver template that should be shared across all the resolver template. I am wondering if there is any way for me to share this code across resolvers. I know I can write up the cdk code to share the same code but anything in appsync to create global functions and call them within resolver response template.

Related

Is Axios.all available in nestjs?

I would like to make a method in service which handle multiple requests at once in my NestJS project.
Right now what I used is the HTTPService from #nestjs/axios
I tried to found resources on the internet about axios.all for nestjs, but I can't really get the exact things I want for NestJS.
So I would like to ask that does Axios.all() exist in the nestjs?
You can see on #nestjs/axios's package.json (here) which version of axios is beign used by that lib. If that version support Axios.all, then it's available. You could retrive the axios instance using this.httpService.axiosRef()
axios.all and axios.spread are deprecated. Just use Promise.all.

MarkLogic Customized REST API Creation without Gradle or Roxy Framework

I want to create a brand new REST API using MarkLogic 9.x.x but without using Roxy or Gradle. I want to point to a file which has list of customized endpoints in basic MarkLogic setup and then keep my customized logic in those modules.
I've gone through the REST API documentation to create one by using CURL so that we can use default APIs provided by MarkLogic.
Any detailed explanation is appreciated.
Management REST api is really your best friend here, it is designed for this purpose. However, creating scripts that make the appropriate REST calls can be cumbersome. ml-gradle can support you with that though. It can generate a shell-script with all curl-statements for you, which you could run as-is, or use as starting point to build out your own set of deploy scripts. For details see:
https://github.com/marklogic-community/ml-gradle/wiki/Generating-a-shell-script
HTH!
Have you considered using XQRS ?, you can create custom REST endpoints with ease using intuitive Function Annotations much like one would do with JAX-RS or Java Spring REST Services. It can be installed and used with or with-out Gradle.
You can keep your custom logic either in these REST functions, or you could write your custom logic in JavaScript code that you then import/invoke from these functions. XQRS provides you with total flexibility. You can make beautiful REST APIs with Human-Friendly URLs that sit directly on MarkLogic, taking complete control of the URL Path. It's solid as a rock and unit tested to death. It scales with MarkLogic - i.e. you add more MarkLogic e-nodes and you automatically scale your REST servers, it's totally free and open source. The project is actively maintained and support is available on GitHub. If you've got a Swagger/OpenAPI interface file, you can generate a MarkLogic Stub too which could save you a lot of time.
Functions simply become available as REST Services based on the Annotations you place on them - and you can pass query/form parameters, cookies and the request body via the Annotations. Check out this snippet for a sample flavour.
declare
%rest:path("/factory/warehouse/wheel/{$wheel-id}")
%rest:GET
function get-wheel($wheel-id as xs:string) {
fn:doc($wheel-id)
};
declare
%rest:path("/factory/warehouse/wheel/{$wheel-id}")
%rest:PUT("{$doc}")
%xdmp:update
function put-wheel($wheel-id as xs:string, $doc as document-node(element())) {
xdmp:document-insert($wheel-id, $doc, map:entry("collections", "wheels"))
};
declare
%rest:path("/factory/warehouse/wheel")
function list-wheels() {
<wheels>{
fn:collection("wheels")
}</wheels>
};
Both responses to date are correct and accurate and help, however the original question is self-answered.
I've gone through the REST API documentation to create one by using
CURL so that we can use default APIs provided by MarkLogic.
That is in fact the answer to your question as stated.
To manually deploy ML rest API, please follow below steps
Create Module DB
Create App Server
Provide details for Module DB, database, port, URL rewriter
Deploy xquery, xsl using qConsole
let URI = path of file
let path = xdmp:document-get($FilePath)
xdmp:document-insert($URI,$path,(), ())
where endpoints.xqy will contains defined custom endpoint for your rest API and internally you can call search:search function to call data from MarkLogic
module namespace endpoints="urn:overstory:rest:modules:endpoints";
declare namespace rest="http://marklogic.com/appservices/rest";
(: ---------------------------------------------------------------------- :)
declare private variable $endpoints as element(rest:options) :=
<request uri="^/getcontent$" endpoint="<xqy file" user-params="allow">
<http method="GET"/>
</request>
Hope this will help

How to share a common mapping template at AWS API Gateway?

I'm having a lot of duplicated mapping templates across endpoints on my AWS API Gateway implementation.
I would like to have a single template defined, and then just tell an endpoint to use that particular template.
Is this possible?
This is not currently supported, but definitely something we can consider in the future as we update the service.
Update: My apologies. Templates are exposed as their own resource. Can you tell me how you are creating your API? I may be able to advise on how to re-use them correctly.

Best practices for REST API that access multiple environments

When writing a RESTful API that needs to access different environments such as a lab/test database and a production database, what's the best practices around setting up the API?
Should there be a #PathParam?:
/employee/{emp_id}/{environment}
/{environment}/employee/{emp_id}/
Should there be a #QueryParam?:
/employee/{emp_id}/?environment="test"
/employee/{emp_id}/?environment="prod"
Should there be a field in the payload?:
{"emp_id":"123","environment":"test"}
{"emp_id":"123","environment":"production"}
In fact I see two ways to handle this. The reason to use one or the other corresponds to what is the most convenient to implement in your RESTful application.
Using a path parameter
With this approach, it should be a path parameter at the very beginning of the resource path. So URL would be like this: /{environment}/employee/{emp_id}. Such approach is convenient if you have several applications deployed under different root paths. For example:
/test: application packaged with the configuration for the test environment
/prod: application packaged with the configuration for the production
In this case, applications for each environment are isolated.
Using a custom header
You could also a custom header to specify on which environment to route. Github uses something like that to select the version of the API to use. See this link: https://developer.github.com/v3/#current-version. It's not exactly the same thing but you could have something like that:
GET /employee/{emp_id}
x-env: test
A reverse proxy could handle this header and route the request to the right environment.
I'm not convinced by the approach within the payload since an field environment isn't actually a part of the representation for element resource employee. Regarding the query parameter approach, it's similar since such parameters apply to the request on the resource.
Hope it helps you,

Sails.js matching up endpoint methods to http methods (GET, POST)

I'm working through the documentation on Sails.js, and have created a basic dev instance according to their "Getting Started" guide:
$ sudo npm -g install sails
$ sails new testProject
$ sails generate users
$ sails lift
These four simple commands will install the platform, create a project, and create the model users as designed.
From my browser, using the default installation port, I can now access http://localhost:1337/users and receive an empty JSON array [] as expected.
Now, should I wish to create a new user, REST best practice dictates that I should use the POST method. POST does indeed work, however out of the box, Sails also allows you to perform GET http://localhost:1337/users/create to generate a new user object.
Reading through their documentation, I have been unable to determine a way of limiting which HTTP methods are allowed to perform various tasks. Is this in the documentation? Or can someone explain where in the Sails stack this (should|could) be managed?
Sails.js provides you with those shortcuts letting you to operate using only GET method for development purposes only. You can disable those in production, if you want, using the configuration noted in the docs:
By default, Sails will create a blueprint action route for each action
in a controller, so that a GET request to
/:controllerIdentity/:nameOfAction will trigger the action. If the
example controller in the previous section was saved as
api/controllers/SayController.js, then the /say/hi and /say/bye routes
would be made available by default whenever the app was lifted. If the
controller was saved under the subfolder /we, then the routes would be
/we/say/hi and /we/say/bye. See the blueprints documentation for more
information about Sails’ automatic route binding.
Besides the default
routing, Sails allows you to manually bind routes to controller
actions using the config/routes.js file. Some examples of when you
might want to use explicit routes are:
When you want to use separate
actions to handle the same route path, based on the HTTP method (aka
verb). The aforementioned action blueprint routes bind all request
methods for a path to a given action, including GET, POST, PUT,
DELETE, etc.