How to create function for an API function not belonging to any model class? - django

So I am using Django/DRF for my backend and I want the client (my web app) to be able to make an API call that looks up tags for an image using Google Cloud Vision API. Obviously, I don't want the client to have access to the API key, hence the server should perform the actual call to Google's API. What I'm struggling with currently is where to put this API function. Do I have to create a model for this (even though there is no db table) or is there some way around that?

Related

Query (HTTP GET) data in Power Apps Portal from Web API with JavaScript

I have a "Starter Portal" Power App Portal. I would like to utilize JavaScript and the Web API for querying data. Documentation states
You can use the Web API to perform create, update, and delete operations across all Microsoft Dataverse tables from your portal pages.
Further documentation only lists the CREATE, UPDATE, DELETE operations, and this API being accessible as
[Portal URI]/_api
And I have found how to successfully authenticate using a helper method to get a token for the header:
shell.getTokenDeferred().done(function (token) { ...}
This allows authentication as the user logged into the portal so I believe all relevant Table Permissions, etc. are applied.
But, I would like to retrieve data (HTTP GET). I know this is possible from the Dataverse Web API.. This api is exposed as
[Organization URI]/api/data/v9.1/
Are these really the same API, just exposed a different way for the portal? Is it possible to use the GET endpoints or the second API altogether, authenticated as a Portal Contact user like the previous operations?
It's the same API but permissions are different, you will need to enable the tables you want to access inside the _api endpoint.
You can read more info at this page: https://learn.microsoft.com/en-us/powerapps/maker/portals/read-operations, there is also an XrmToolBox tool to assist you in this operation (but I didn't try it) https://www.xrmtoolbox.com/plugins/PowerPortalWebAPIHelper/
Regarding the Web API calls, I released a new tool to create them (similar to CRM REST Builder) I also added a "Portals" syntax (is in preview) but the generated urls are the same. Link: https://github.com/GuidoPreite/DRB

Which type of Xero application should we use?

We are creating an integration application which will sync data between Dynamics CRM and Xero. We are now at the stage where we need to decide which type of application we should use to connect to Xero and perform operations.
The application will be used by multiple Xero Customers. So our application should serve multiple Xero users.
We will have web api which will call on Dynamics CRM events(Create, Update Contact etc.) and will update the data in Xero.
So our web api should connect to Xero and perform operations in Xero. We tried using Public application but it generates the token that is valid for 30 minutes. The web api should communicate to Xero without any time limitation.
Please suggest how we can achieve this.
You should begin developing your integration using a public application, and get in touch with Xero to register for becoming a partner application (which will give you the ability to request long-term tokens). The process is documented here: https://developer.xero.com/documentation/auth-and-limits/partner-applications

Architecture of a product search engine

I have developed a product search engine using AWS API Gateway, Lambda, ElasticSerach services. When user queries for a product, web server forward those request to API GW, then Lambda function is called and Lambda runs a search query in ES and sends back the results.
This works fine but I want query results to be cached somewhere if it returns more than 40 items so users can move to next page and so on without triggering the Lambda again and agin.
Is there an easy way of doing this without creating a web service using Node.js or something like that, I was checking ElastiCache but I couldn't find a proper use case.
Any idea how this can be achieved without maintaining a 24/7 web service?
Thanks!

How to create an API endpoint without a model in Loopback?

I understand we can create remote methods on models which will expose an endpoint. However, is there a way to expose an endpoint without a model?
For example, if I want to create an endpoint checks the version of a native app. I don't need a model to back this endpoint. The endpoint would simply check the passed in version and respond.
Does this construct exist within Loopback? Or does it need to be done within the context of Express?
You can use express routes as shown in Loopback's Getting Started example.

Loopback Rest API without connecting to database

I am planning to use some service from other SDK, but I don't know how to create a Rest API without having to connect to datasource. Currently, I have to create a remote hook inside a loopback database model which are not even relevant to each other. For example, I would like to call a Text Message Service API from Twilio, but I have to create the remote hook in Class Model since it's connected the database. Can I create a API without creating a model and connected to the datasource.
For using 3rd party REST APIs you can use a loopback-connector-rest datasource. The documentation for the connector can be found here.
Otherwise, you can create a model without connecting it to a datasource by setting it up in your model-config.json as follows:
"ModelName": {
"datasource": null
}