Use single custom domain + URL for all firebase function calls - firebase

I'd like any https request to MY_CUSTOM_DOMAIN/functions/** to go to firebase functions.
I'm aware of the below solution:
Use custom domain for firebase function http calls
https://firebase.google.com/docs/hosting/functions#create_an_http_function_to_your_hosting_site
My understanding is this requires adding every single function to this list though. It would make my firebase.json file pretty long and probably I'll forget to update it on future functions.

You can refer to this documentation to use the wildcards and avoid repeating URL paths. Seems like you have to mention every function you are using for routing.
There is one workaround, As you are concerned about firebase.json. You can define an index function which determines the specific path by using req.path and calls other Cloud Functions to handle the respective request.
Also have a look at this thread1 & thread2

Related

How to properly mock API results for testing with NextJS and MSW?

First of all, if I should ask this question elsewhere please let me know, as I'm not sure where it belongs.
I have a working application with NextJS and MSW, where I can capture the server-side API requests with MSW and return mocked JSON results.
The issue I have is that there are probably about 15 API calls that I need to mock in order to test my application properly
While I could just call each one of these manually, copy and paste the results into a file and then just return that data from the file when I capture the API call, this not a very scalable solution, especially if the back-end API changes.
Question: What are your best methods for automating the generation of these results?
In the past I have created JSON files that have all of the URL paths and query parameters explicitely listed, and I would parse through this file and query every endpoint, and then I had template files which would be used to re-populate my fixtures directory with all of the mocked responses, however this was also very cumbersome.
(For reference, the API has a somewhat similar structure to this one: https://api.gouv.fr/documentation/api-geo, where there are multiple endpoints for fetching data, and each endpoint supports a number of different query parameters to tweak the call.)

Is using Firebase cloud function library better than direct http call to the same cloud function url

I have an Express server running in firebase cloud function.
Currently, I am calling this cloud function from my client (assume it's a web client) using direct http call to url that was provided to me to access the function.
However, there is another method to call this function which is using thr firebase cloud function library for the client.
My question is : what advantage do I get ( in terms of speed ) if I use the library instead of the direct http call.
My assumption is that the library uses a web socket to accesd the function whereas the direct http call uses http call
I couldn't find anywhere in the documentation saying which one is better
Callable functions invoked using the Firebase SDK were not designed to provide any sort of increase in performance over a normal HTTP request. In fact, on average, you will hardly notice any difference between the two.
It's better to pick the one that meets your needs and preferences rather than thinking about performance. But if you really must choose the one that's faster, you should benchmark your choices yourself to see which one is better for your specific case.
See also: Are Callable Cloud Functions better than HTTP functions?

Use of Inbuilt rest end point to invoke module in ML database

I am using inbuilt rest end point in Marklogic that allow me to call modules in stored in module database in Marklogic.
http://localhost:8000/LATEST/invoke?data-urlencode=module=/modules/module.xqy&database=databasename&data-urlencode=vars='{"word1":"hello","word2":"world"}'
Does it also provide any option to call direct function present within lib module?
Using vars option it allows us to pass external parameter to the invoking modules. It seems that vars option only allow to pass primitive values to external parameter to invoking module.
But how we can use this vars option to pass XML data to invoking module so that it can be access through external variable defined within module.
Any suggestion would be appreciated.
Note : I am using postman for testing of rest API.
Many thanks.
Since your goal is to get to a library function, consider creating a REST extension instead of using /invoke with a main module. A REST extension can implement your choice of HTTP verbs and accept input in whatever for you'd like. The extension can then convert those inputs to function parameters and call the function.
For more information about REST extensions, see Extending the REST API, which includes an example XQuery extension.

Getting a list of target endpoints

Can I get a list of target endpoints in a javascript policy?
Let's say I have a proxy endpoint that connects to multiple target endpoints. Can I write a javascript policy so that if a request is made to a specific url on that proxy, it will make a call to all the target endpoints and aggregate the results?
Yes that's possible. The apiproxy definition itself holds all the target endpoints defined for it.
For example:
curl -v https://api.enterprise.apigee.com/v1/o/{org}/apis/{api}/revisions/{rev}/targets
would give you the list of all targets.
Then you can get each target URL from the list by calling:
curl -v https://api.enterprise.apigee.com/v1/o/{org}/apis/{api}/revisions/{rev}/targets/{target}
You can parse out each URL in a for loop and then make a request to each of these URLs. If your requests a simple GET calls without any variation in the request object like headers, body etc. then a simple for loop would be good enough.
For example:
var geocoding = httpClient.get(URL);
context.session["geocoding"] = geocoding;
This piece of code can be called in a loop for all the target endpoints that you might have.
The only catch here is that, to get the target endpoints you are making a management api call from the runtime layer. Which means if at any point of time the Apigee management layer is down for maintenance or experiencing degraded service due to scheduled maintenance, your runtime calls would tend to fail. The other solution could be to isolate the two scripts:
Get the list of endpoints in one javascript and maybe store the URLs in cache (populateCache policy) or keyvaluemaps (given that proxy endpoint URLs won't change too often)
Read the list of endpoints from cache or kvm and then trigger another javascript that can make calls to these endpoints and then aggregate the response.
There is not a way to call a target endpoint from JavaScript. In fact, you can only call 0 or 1 target endpoints for a single call to the proxy, not multiple target endpoints.
You can call make multiple HTTP requests from within JavaScript using httpClient, and aggregate the results, but not target endpoints. An example of this is found here.

when to use a Meteor Method vs normal function?

I've got, I think, a relatively simple question. I'm wondering in Meteor, especially when I'm defining server-side functions that I want the client to be able to call, when do I use a method vs a normal function? Why can't I just use a global function in my Meteor server code instead of defining a Meteor Method?
thanks!
Functions defined only the server are only accessible to server code (even if defined globally). So for example, if you had a function defined in server/util.js it would not be available to the client.
You could, however, define a function that was global to both the server and the client by placing it outside of the server and client directories, e.g. in lib.
Generally, you would choose to create a method over a function when you want a side effect which should only be produced on the server. Examples:
you need to sign a URL and keep the key only on the server
you need to perform a database operation that can only be done on the server (due to limitations of minimongo)
Important note - method calls from the client are asynchronous (you need to provide a callback function to know the result of the method), so that may also factor into your decision.

Resources