I have an API that want to access whenever a user clicks on a certain state on the US Map. I’d like to get the state id (ex: CA) and send it to the netlify function.
The netlify function would then get everything I need from the API and return it to the client side js file I have.
Is this possible?
What stack are you using on front end, may be I can explain better in that case.?
For now my understanding is just call netlify API on onClick method and then pass the id as params. This is a generic way of using 3rd party API.
If you want to know more in details, provide more information. e.g API url you are trying to use.
Related
I made a nodejs application that starts from index.js.
Then, index.js launches puppeteer and injects bot.js on a headless-api page by addscripttag function.
I made index.js sets a cookie for conveying initial values before injecting javascript, but I need more common way to exchange data.
I thought two ways; the first is using cookie, and the second is networking via socket connection.
Is there other way for send and receive data between index.js(node) and puppeteer(headless chrome)?
First, puppeteer IS nodejs side application, so they have a single environment and you don't need to "send" anything. Just pass data around as you'd do in any other JS code. I assume you want to transfer data between page and nodejs then.
To pass data from nodejs to page use page.evaluate. You can call any code in page context, ranging from simply setting some variables to directly calling whatever functions with necessary arguments.
To initiate transfer from page side to nodejs, first register a nodejs-side callback function with page.exposeFunction and then call it from page code and it will be executed in nodejs context. Just like in previous case, everything else depends on code of that function. It can be as simple as storing whatever argument you pass to it in some variable or directly perform with data pretty much whatever you want.
I have a few documents in my database and I've designed search functions for them. So I want to use curl in cmd and call the function so that I can run the searches and print the results in cmd only.
For example, I have a function where I'm passing the "userID" and I want all relevant documents. So I need to pass that value in the code or can I specify this(params) in curl.
If not curl, what other REST API options do we have to call custom JavaScript functions?
One approach is to create a REST API server and use either the invoke or resource service extension endpoints to invoke your script.
For information about standing up the REST API, see:
http://docs.marklogic.com/guide/rest-dev/intro#id_97899
For information about invoking code, see:
http://docs.marklogic.com/guide/rest-dev/extensions#id_72813
For information about a resource service extension (which requires that your code conform to conventions), see:
http://docs.marklogic.com/guide/rest-dev/extensions#id_21018
Hoping that helps,
I need to be able to allow a customer (or group of customers in this case) to register for the store, and I need to be able to reference that group of customers in the code somehow, for example:
if (currentUserIdOfSomeSort === 9) {
// do something
} else {
// do something else
}
THE CATCH: I need to be able to accomplish this without the need for a person to go into BC and change a setting on the customer - if I have to go and assign the customer a specific group id, then that is not a solution because it involves human intervention.
Everything also needs to be local, as in I am not able to configure an external server to make API calls for specific information (for example, if I added a 'code' field to the registration form - I already asked, this will not create a new variable for that field, and I am told you would need to use a separate server to make the API call to return that info, something I do not know how to do)
Any ideas would be greatly appreciated
There is not a way to create your own custom global variables as these are functions of the core app. If you wanted to call to the API, you'd need to use Heroku (or your own server of choice) to make a request to the API. It can be a purely cURL request or you can use an API client.
curl --request GET \
-u "_username_:_API_key_"\
https://store.mybigcommerce.com/api/v2/customers/{id}.json
You can pass that into a js file hosted on the same server and then load the javascript on your storefront.
<script src="https://myserver.com/favoritenumber.js"></script>
You'd also need to do some validation that you were displaying this to the correct customer. I'd elect to use CustomerID instead of CustomerName and validate against this.
i am working on google map api.
i've created a function named as codeAddress which shows the map of state/city given by user in a text field named on a click event (button name show map). I want to show the map on another page on a click of same button. please help me how can i call the codeAddress function on another page?
You are trying to implement Client-Client protocol. Unfortunately, you'll need third part in this system^ server. There is several options:
Long polling from the second page to server-side Stack. Stack is abstract storage with function name and arguments. First page puts function to the stack (simple AJAX request) and maximum after a polling lag the second page will receive this Stack item.
Use server as connector and make peer-to-peer connection. After this you'll be able to send messages to the opened pipe.
Use something like socket.io - Pub-Sub pattern realization written in Javascript (Node.js)
All these options are not trivial and requires some additional work.
I need to create a feed based on changed documents. I figured the _changes api would be perfect in this case. Ie simply store the last sequence id client side, so we can use it to limit the results in the next call to _changes.
Currently, the application performs the following:
calls _changes with since/filter parameters
calls a show function for each id in the _changes feed
renders all changes into the customer feed
What I would like, is to be able to call a list function on the entire _changes result in a single request. This would remove the need to explicitly parse the _changes result on the client, and move that functionality to the server.
The question: is this even remotely possible?
I have been trying to implement a view, doing "almost" the same thing as _changes, but without any real luck.
This is not possible at the time, and the _changes API is different enough from regular views that it's not entirely straightforward to implement.
There is a ticket open in the CouchDB issue tracker, but it hasn't been updated in quite a while.