PHP Classes

File: server/routes/api.php

Recommend this page to a friend!
  Classes of Kamil   PHP API Tutorial Training Server   server/routes/api.php   Download  
File: server/routes/api.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP API Tutorial Training Server
Implementation of a REST API for learning purposes
Author: By
Last change:
Date: 2 years ago
Size: 1,527 bytes
 

Contents

Class file image Download
<?php

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::get('basic-auth', function(){
    return
response()
        ->
json([
           
'status' => 'ok',
        ]);
})->
middleware('auth.basic.once');


Route::get('plain/users', function() {
    return
response()
        ->
json(\DB::table('users')->select()->limit(20)->get());
});

Route::get('plain/cookies', function() {
    return
response('ok')
        ->
cookie('test', 'value', 10)
        ->
cookie('another', 'cookie', 10);
});

Route::get('oauth2/users', function(){

    return
response()
        ->
json(\DB::table('users')->select()->limit(20)->get());

})->
middleware('auth:api');

Route::get('plain/files/{type}', function($type) {

   
$types = [
       
'csv' => 'text/csv',
       
'css' => 'text/css',
       
'js' => 'text/javascript',
       
'png' => 'image/png',
    ];

    if(!isset(
$types[$type])) {
        throw new \
Symfony\Component\HttpKernel\Exception\NotFoundHttpException();
    }

    return
response()->download(
       
base_path() . '/resources/assets/sample-files/sample.' . $type,
       
'sample.' . $type,
        [
           
'Content-Type' => array_get($types, $type),
        ]
    );
});