Shopify request middleware - shopify

I want to know, is it possible to add a middleware or request interceptor to Shopify?
Something similar to express, to add some custom behavior or set any values between the request and the response.
I want to read some values from the request object and take some decisions and send that to the response.
Any guide or documentation for this.
Thanks!!

No, not really.
You can customize a Shopify theme using Liquid, their templating language. Liquid has a {{ request }} object which contains the path and domain of the request. You could adjust the body of the response based on that but it isn't like Express middleware.
Some people host their own website and use Shopify's buy buttons or JS buy SDK. If you do that then you can use Express if you want.

Related

Access cookies through an API on AMP page

I am converting a page to google AMP and need to access cookies to set a view of a division. I am thinking of creating an API for this.
The API will just return all the cookies available on my domain in JSON format. I will hit the API using <amp-state> component and store the returned JSON. Then will take actions according to this state.
Is this a valid approach to use in AMP? Is there any security flow in this?
Using amp-list is the right approach in this case. amp-list makes a request to your server, which can read the cookie and return an appropriate JSON response. You can render then the form / button inside the amp-list using amp-mustache.
This samples demonstrates how to do this: https://ampbyexample.com/advanced/favorite_button/.

how to add custom callback URL to Coinbase

I'm using Coinbase service to dealing with Bitcoin gateway.
I know i can put callback url in the merchant settings page of my account.
But i need to update it in each order. It can be done using API. but it's so boring.
I need something like this :
Adding data-callback="custom_callback_url" in the Anchor tag.
<a class="coinbase-button"
data-code="code_here"
data-callback="custom_callback_url"
href="https://coinbase.com/checkouts/code_here">Pay With Bitcoin</a>
<script src="https://coinbase.com/assets/button.js" type="text/javascript"></script>
With coinbase's API, you will have to set the callback URL while generating the code!
There is more info on how to generate the code here: https://coinbase.com/api/doc/1.0/buttons/create.html

Wordpress widget with xml asynchronous integration

I have a task to do where I need to make calls to an external xml api to fetch data for an event calendar in the sidebar of a site. The date will be changed with JavaScript and then i need to make another call to refresh the data. Can somebody give me an idea about how to cleanly set up an action or function somewhere that I can direct an Ajax action to? It's easy to set up a widget with the correct HTML etc but where does the Ajax connect to? Ideally when the content initially loads on the page it would use the same function that the post is going to use to generate the HTML on the server side.
Any tips would be appreciated. This is an xml api...no option for json or jsonp so credentials including a token and user I'm assuming will have to go somewhere in my widget, something like a proxy function?
It sounds as if you're asking about making cross-domain AJAX requests, AKA the "same origin policy."
The same origin policy prevents document or script loaded from one origin from getting or setting properties of a document from a different origin (domain). See http://www.mozilla.org/projects/security/components/same-origin.html for a more detailed description of the policy.
See Ways to circumvent the same-origin policy for a good description of the options available to circumvent this limitation.
The short answer is that unless you have control over the domain to which you're making AJAX requests, your best bet is probably to set up a simple proxy that lives in the same domain where your AJAX is running, which will forward requests to the destination. Doing a google search on "simple AJAX proxy" will get you a host of results, including pre-built proxies in a variety of languages.

Yii Framework, JSON API, Restricted by URL

I am trying to build an API service for my Yii based website,
I have create an API controller with all the functions that returns objects in JSON format.
I also created a system to generate API keys for a specific URL... but I cant seem to understand how to detect the url from where the call is being made to my api so I can compare and validate.
I have tryed with HTTP_REFERER ...not working...
Any idea how is this possible ?
Thanks
try this:
Yii::app()->request->urlReferrer
or
Yii::app()->request->host
or
Yii::app()->request->hostAddress
for more details see http://www.yiiframework.com/doc/api/1.1/CHttpRequest

How to format an HTTP PUT request?

I am using the Yahoo Placemaker API and would like to send a request but I am getting confused as to how to send the request. The request is composed of a URL and a document and inside the document, there are a bunch of parameters. Please see below.
http://wherein.yahooapis.com/v1/document
documentContent=Sunnyvale+CA
documentType=text/plain
appid=my_appid
How do I format the URL into a request is it like so?
http://wherein.yahooapis.com/v1/documentContent=Sunnyvale+CA?documentType=text/plain?appid=my_appid
I would like to use this the Placemaker service for a Mac app written in objective-c.
Any suggestions would be great. Thanks.
You don't. The URI and the request body are different things.
It would be helpful if you explained why you're asking. What platform/API/language are you using?