Services Web Services Web
John Samuel
                          CPE Lyon
                        Année: 2017-2018
                        Courriel: john(dot)samuel(at)cpe(dot)fr
                        
$ sudo apt install apache2 php7.0 libapache2-mod-php7.0
                        $ sudo a2enmod rewrite
                              $ sudo service apache2 restart
                        
		<?php 
                               phpinfo()
                              ?>
                        
                         
                        Vérifier le fichier /etc/apache2/sites-available/000-default.conf
                        
                          <Directory "/var/www/html">
                        
                               AllowOverride All
                          </Directory>
                        
 $ sudo service apache2 restart
                        
		
                        
                          RewriteEngine on
                        
                          RewriteRule ^test.html$ /index.php
                        
                        
                          RewriteEngine on
                        
                          RewriteRule "^.+.html$" /index.php
                        
                        
                          RewriteEngine on
                        
                          ErrorDocument 404 /404.php
                          RewriteRule "^.+.html$" /index.php
                          RewriteRule "^(.+)/index.php$" /index.php?lang=$1
                        
                        
                          RewriteEngine on
                        
                          RewriteRule "^.+.html$" /index.php
                          RewriteRule "^(.+)/index.php$" /index.php?lang=$1
                        
                        
                          <?php
                        
                          $language = "fr";
                          if($_GET["lang"]) {
                            $language = $_GET["lang"];
                          }
                          if($language == "en") {
                            echo "Hello!";
                          }
                          else if($language == "fr") {
                            echo "Bonjour!";
                          }
                          ?>
                        
Une architecture REST doit respecter les six contraintes suivantes
À interface uniforme
Un client REST n'a besoin d'aucune connaissance préalable sur la façon d'interagir avec une application ou un serveur particulier au-delà d'une compréhension générique de l'hypermédia.
 
                  Différents niveaux [2]
Les codes les plus courants sont :
                    $ curl example.com
                  
		
                    $ curl -I http://localhost/index.php
                   
                  
                    HTTP/1.1 200 OK
                    Date: Thu, 26 Apr 2018 18:54:18 GMT
                    Server: Apache/2.4.18 (Ubuntu)
                    Content-Length: 14
                    Content-Type: text/html; charset=UTF-8
                   
                  
                    $ curl http://localhost/index.php
                   
                  
                    $ curl -X GET http://localhost/index.php
                   
                  
                    $ curl -X POST http://localhost/index.php
                   
                  
                    $ curl -X POST --data 'user:abc' http://localhost/index.php
                   
                  
                    $ curl -X POST -d @file.json http://localhost/index.php
                   
                  
                    $ curl -X PUT http://localhost/index.php
                   
                  
                    $ curl -X PUT --data '' http://localhost/index.php
                   
                  
                    $ curl -X PUT -d @file.json http://localhost/index.php
                   
                  
                    $ curl -X DELETE http://localhost/index.php
                   
                  
                    $_SERVER['REQUEST_METHOD']
                   
                  
                    $data = json_decode(file_get_contents('php://input'), true);
                   
                  
                     echo http_response_code(521);
                   
                  
                        
                          RewriteEngine on
                          ErrorDocument 404 /404.php
                          RewriteRule ^(.+)/$ /index.php?resource=$1
                          RewriteRule ^(.+)/(.+)$ /index.php?resource=$1&id=$2