Created
September 27, 2017 05:59
-
-
Save FMCorz/244e16b2deef4c958015e68a50d293f2 to your computer and use it in GitHub Desktop.
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
<?php | |
function get_routes() { return [ | |
[ | |
'regex' => '/courses', | |
'methods' => [ | |
'GET' => [ | |
'function' => 'core_course_get_courses' | |
], | |
'POST' => [ | |
'function' => 'core_course_create_courses', | |
'args' => function($params, $data, $options) { | |
return ['courses' => [$data]]; | |
}, | |
'return' => function($response) { | |
return reset($response); | |
} | |
], | |
] | |
], | |
[ | |
'regex' => '/courses/([0-9]+)', | |
'methods' => [ | |
'GET' => [ | |
'function' => 'core_course_get_courses', | |
'args' => function($params, $data, $options) { | |
return ['options' => ['ids' => [$params[0]]]]; | |
}, | |
'return' => function($response, $params) { | |
return reset($response); | |
} | |
], | |
'PATCH' => [ | |
'function' => 'core_course_update_courses', | |
'args' => function($params, $data, $options) { | |
return ['courses' => [['id' => $params[0]] + $data]]; | |
}, | |
'return' => function($response) { | |
return null; | |
} | |
] | |
] | |
] | |
]; } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment