Created
June 9, 2021 08:15
-
-
Save sahilkashyap64/685f8757e5dd3be34ac548800f28ccca to your computer and use it in GitHub Desktop.
Laravel Use gzencode compression in rest api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Route::get('channeldayschdeule', 'DemoController@channelDaysSchedule'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function channelDaysSchedule() { | |
$record= DB::table('gracenote'); //use select to limit data | |
$reco=$record->get(); | |
$response = [ | |
'success' => true, | |
'date'=>date("Y-m-d"), | |
// 'count' => $reco->count(), | |
'data' => $reco, | |
'message' => 'Schedule data for 3 days found', | |
'response_code'=>200, | |
]; | |
$responsejson=json_encode($response); | |
$data=gzencode($responsejson,9); | |
return response($data)->withHeaders([ | |
'Access-Control-Allow-Origin' => '*', | |
'Access-Control-Allow-Methods'=> 'GET', | |
'Content-type' => 'application/json; charset=utf-8', | |
'Content-Length'=> strlen($data), | |
'Content-Encoding' => 'gzip' | |
]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment