I want to call rest API from view in YII.I know how to call it from simple PHP.
From here
But I dont know how to call it in YII manner.what is the right way to call it in YII?
As Yii 1.1
you've not a framework class to do the requests, but you can use Guzzle a powerfull PHP HTTP client:
docs to REST operations
Github guzzle
As Yii 2.0
you can use yii2-httpclient:
github yii2-httpclient
yii2-httpclient documentation
There isn't Yii way to get the data from API so you can use:
$output = file_get_contents('http://www.hpgloe.com/json/getrec/?lat=37.234&lon=-122.234');
After that you can use CJSON helper to decode the data. For example:
$response = CJSON::decode($output);
Related
How to get this list by using ServiceNow API?
The easiest way to achieve that is by using REST API, here is how the call will look like:
https://yourinstance.service-now.com/api/now/table/sys_choice?sysparm_query=name=incident^element=category
If you are only interested in label the call will look like this:
https://yourinstance.service-now.com/api/now/table/sys_choice?sysparm_query=name=incident^element=category&sysparm_fields=label
You didn't clarify whether you're looking for client-side, server-side, or REST API, but here's the answer for server-side:
var gr = new GlideRecord('incident');
gr.get('e8caedcbc0a80164017df472f39eaed1');
gs.print(gr.category.getChoices());
This getChoices() API is a GlideElement API, so you call it on a field element in a server-side GlideRecord.
You can find this API documentation here.
I wrote an API documentation (JSON\YAML) using Swagger and now I'd like to get the Model example for each RESTful and use It to validate my API output using PHPUnit test.
Is there a way to do that?
Thank you.
Here's a repo that will allow you to do assertions on your schema with PHP unit. I hope it helps:)
https://github.com/Maks3w/SwaggerAssertions
I'm developing a software using Symfony framework. This software contains two part: back end(server side) and front end(client side). In front end using a angular framework for UI and not using a twig (twig is a symfony UI framework). In back end me should create API for using a Front end .
Now:
user upload file in front end and using a post method for sending a file in back end. I should create a controller for post method (this is not problem). The problem that occuring is I want to get file with symfony framework.
I search in the web and read all things about upload file with symfony, but all of them using twig and not using a raw API.
Can any body tell me, how to get post data with symfony?
Your question is not very understandable.
You will find in the official documentation:
a cookbook about handling file upload with Doctrine
how to handle Post data from a form (can't post more than two links in my answer, but look at the Form chapter of the doc, and search more specifically about $form->getData() method)
how to manage Post data in a less specific context.
Hope it will help.
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
Is it true that most of the web methods available in SugarCRM's SOAP API are now deprecated and replaced by set_entry() and get_entry() ?
For example, if I want to create a new lead should I use create_lead() or should I stick to set_entry() on "Leads" instead?
Not exactly, version 5.2 has the SugarCRM SOAP v1 api and version 5.5 has version1 api and a version 2 api.
You just have to use different urls to access the api that you want in 5.5.
That appears to be correct. I use get_module_fields($session_id, 'Contacts') to get the fields for whatever module I am creating or updating. Replace Contacts with whatever module you are working with.