Show api-blueprint documentation of my REST API doesn't work - php

I've the following situation: I built a REST API using zend (not apigility but single packages like zf-rest).
Now I want to document my API (the endpoints, request and response types etc.). For this purpose I created a folder "data" and a subfolder "api-blueprint" under my project directory. Here I stored some files with markdown. So I have:
/myproject/data/api-blueprint/index.md
/myproject/data/api-blueprint/hal-entry-point.md
...
My expectation is that I can open a browser and call
mydomain.com/api/rest/myproject
(this is the root) and see the content of hal-entry-point.md, so I get an overview about the supported endpoints. But I can't get it to work. Is there a special framework which I forgot to install or a configuration of zf-rest, zf-hal ...?

Related

How to create Custom REST API in SuiteCRM

Im new to SuiteCRM.
Can any one tell how to create a REST API from scratch for a custom module.
I went through the developer guide, but i need to know like in which file those REST API call has to be made (Referring the PHP example from the below link)
http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_6.5/Application_Framework/Web_Services/Examples/REST/PHP/Creating_Documents/#Overview
If you want to add your own API to your module, you probably are looking for https://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_6.5/Application_Framework/Web_Services/Extending_Web_Services/
The example code you posted calls the REST API from the "outside" and works independently of Sugar.
So you can just save the example anywhere as test.php and run it with php -f /path/to/test.php.
You could also save it e.g. in the Sugar root dir to make it accessible to the web and just call it from your browser's address bar.

Make GET request from Silex to external site

I'm trying to make a GET request to an external site from my Silex application. The only guide I can find about GET requests is the 'sub-Request' guide in the Silex documentation:
http://silex.sensiolabs.org/doc/cookbook/sub_requests.html
This is ignoring the base URL and looking at my application.
Does Silex have a provider which can make external GET requests? Or do I have to use pure PHP (for example HttpRequest: http://php.net/manual/en/httprequest.send.php)
A subrequest is not what you are looking for (Silex docs: “simulate requests against your application” – emphasis added).
Chances are that you don’t even need a library, as (with the default PHP configuration) you can simply use file_get_contents() – or other file functions – with a remote URL. You will only need a full-fledged library if you have special needs, such as setting custom headers etc.

Google App Engine host routing

I'm trying to deploy an Google App engine app with this setup:
www.domain.com -> Wordpress Frontend
app.domain.com -> AngularJS Backend
api.domain.com -> Rest API used by Angular Backend
Can I achieve this using the basic app schema? Or should I use the modules API?
My main worry about using modules is that they use different instances, increasing the billing. Am I correct?
Modules API is your best bet in this case. You can set automatic scaling to all modules so that new instances are only spun up when there's requests.
It's completely up to you...
Depending on how you structure your project you could do it in either way but of course with Modules things would be a lot nicer organized, although yes, it would increase your monthly bill, while with a single default module your bill would likely to be smaller but your code organization - messier.
If "api.domain.com -> Rest API used by Angular Backend" uses any backend language other than PHP (Wordpress) then you would have to run them as two separate modules/projects since you cannot have both PHP and Python/Java/Go runtimes on the same instance.
If your "app.domain.com -> AngularJS Backend" part consists of static files only and no backend code (php/python/go/java) then that wouldn't require running instances as everything would be served from Google's frontend servers and not directly from your instances (the static files are normally not even included with the code you deploy unless you specify that you want that in app.yaml).

Combining Angularjs and CodeIgniter

I am working on an existing site written in CodeIgniter and we are looking at using AngularJS for some pages that require a lot of frontend functionality but we don't want to replace all all CodeIgniter views (at once (yet)).
So i click a link that's controlled by angular's router and it is handled by javascript but next link could be a "normal" request that should handled by the CodeIgniter framework.
Is there some elegant way to combine these two methods? I don't really mind some extra client side overhead because the site is not running in production yet.
It sounds like you're looking to gradually make less use of CodeIgniter's (CI) routing as your angular application grows. This is not difficult but requires a lot of detail. Which method will work depends on your project structure. Note: I removed index.php from Code Igniter URLs, so the paths below may be different than default.
1) CodeIgniter installed in root
If CI is installed on the root of your server, you can create a folder within CI (for instance I have an "ng" folder). Your project will look like:
/controllers
/models
/ng
(etc)
/index.php (code igniter index file)
place an .htaccess file within /ng with the following:
Order allow, deny
Allow from all
This allows the files within /ng to be directly accessed, rather than sending those requests back through CI's routing system. For example you can load this directly now:
example.com/ng/partials/angular-view.html
The main web page will still be created by CodeIgniter, but it can now include Angular assets, such as partial views, etc. Eventually you can replace most of what CodeIgniter is doing by just returning a simple page, and having Angular load partial views from /ng like it's designed for.
This method is nice because CodeIgniter can control whether that initial page is loaded at all (via some user authentication code in your CI controller). If user isn't logged in, they are redirected and never see the Angular app.
2) CodeIgniter in Directory
If CI is installed in a directory, such as example.com/myapp/(code igniter) you can simply create a directory next to it, example.com/myappNg/
/myapp/
/myapp/controllers/
/myapp/models/
/myapp/(etc)
/myapp/index.php (code igniter index file)
/myappNg/
/myappNg/partials/
/myappNg/js/
/myappNg/(etc)
Now in your Angular application, you can request resources from CI by making paths relative to the domain root, rather than relative to the Angular app. For instance, in Angular, you will no longer request a partial view from the Angular folder partials/angular-view.html, rather you'll want to request views from CI /myapp/someResource. Note the leading /. "someResource" can return an html document, or JSON or whatever you're doing with Code Igniter in the first place.
Eventually you can replace the number of paths which reference /myapp/. Once you no longer use CI for anything, you can simply place your Angular index.html in /myapp/ and it will continue to reference your paths at /myappNg/.
TL;DR Make your Angular app fully available and decouple it from CodeIgniter. Gradually move toward using Angular partial views and other JSON sources instead of linking to CodeIgniter pages. Eventually replace your CodeIgniter endpoint with an HTML file which bootstraps Angular.
Your best bet is to keep your backend code separate from the angular code
and use the codeInginter code as an API
/Codeigniter Code
/Angular Code
Because CodeIgniter comes with its share of security feature this should be your best bet
I've never used Angular - nevertheless this may help.
So i click a link that's controlled by angular's router and it is
handled by javascript
Does this JavaScript make an Ajax request to one of your CI's controllers? If so, CI now has the is_ajax_request() method, which allows you to check if a request (POST or GET) is coming via ajax. You can proceed differently based on a request coming from Ajax vs a normal request.
User guide (bottom of the page): http://ellislab.com/codeigniter/user-guide/libraries/input.html
Hope it helps!
I inherited a CI app and I'm using Angular with CI mainly for routing requests. In my case I am not using Angular templates, so I use a ' ' empty but with a space parameter for the template option in my $routeProvider config. This allows me to do the usual CI ajax requests without too much change to the original server-side code.
angular.module('my_app', []).
config(['$routeProvider', function($routeProvider) {
$routeProvider.
when('/', { template: " ", controller: my_routes.mainpage}).
when('/design/:designId/:action', {template: " ", controller: my_routes.show_design}).
when('/vote_design/:designId', {template: " ", controller: my_routes.vote_design}).
otherwise({redirectTo: '/'});
}]);
To addition to the answer given by Aaron Martin, one can also use it as a client - server approach.
Lets say we make 2 folders in root of our project :
Client
Server
Client folder will contain all the code of AngularJS and the client side libraries including the Bower and Npm libraries.
The routing of the client side will also be handled by AngularJS router.
There will be factories or services which will act as providers for angularjs on client side.
Those file will contain the code of sending request and receiving response from server side.
Server Folder will have the code of Laravel or CodeIgniter or Any other PHP framework.
You will create all the APIs of the requests and develop the functionality accordingly.
Hence the PHP section (Server Directory) at the whole will be storing all the Media Files and Database Files. Moreover it will also have any receiving links for RSS feeds and so on.
The Client shall just receive all the response in JSON or XML format when it requests on any API on its server..
This according to me is one of the finest practice for developing Webapps.
I picked up a CI site from another programmer I work with that is on leave for a few months. Our site is build mostly with a lot of angular due to the the nature of its purpose. Our solution was a little different.
All that varies from the standard CI framework is a couple folders: js\angular\controllers andjs\angular\modules in CI's application folder, to hold all of the angular model and controller files. Then load the angular docs into the application base folder.

PHP create a centralized dispatcher for REST like api

hi i am not sure if this is restful related, i think it is , but please do correct me if i am wrong.
so basically i want my server, which is written in PHP, to respond to different api requests, so for example
http://www.myweb.com/api/content/video/get?id=1 which will return a json object that has information regarding of a video of id=1
however, i can also have the following api to be called
http://www.myweb.com/api/content/music/get?name=biever
i want to create a centralized dispatcher, a php file that sits in the api directory in the server, so whenever a request is made where api appears in the RESTful link (which is in both example above), it shoudld 'intercept' these requests, and examine rest of the path to call the function accordingly. so for example
in controller.php in api directory
it will see, oh you are calling content/video, i will do some pre processing (say, adding video name or something) then direct the method call to content/video/get
how can i, in php, make sure that all the requests will go through my controller file first?
By default URLs are mapped to PHP files in your file system. You can't control this in PHP. By the time your PHP is run, you're too late. So you'll need to look into rewriting the URL at the webserver-level. If you're using Apache look into mod_rewrite.

Categories