Bulletphp 튜토리얼 3

Bulletphp 튜토리얼 3

1 사전 작업[ | ]

2 index.php 수정[ | ]

<?php
require_once 'bulletphp/autoload.php';

$app = new Bullet\App();
$app->path('/posts', function($request) use($app) {
	$app->get(function($request) use($app) {
		return "글 목록 보기";
	});
	$app->post(function($request) use($app) {
		return "새 글 작성하기";
	});
	$app->param('int', function($request, $id) use($app) {
		$app->get(function($request) use($id) {
			return "[$id]번 글 보기\n";
		});
		$app->put(function($request) use($id) {
			return "[$id]번 글 수정\n";
		});
		$app->delete(function($request) use($id) {
			return "[$id]번 글 삭제\n";
		});
	});
});
echo $app->run(new Bullet\Request());

3 테스트[ | ]

[root@zetawiki myapi]# curl http://zetawiki.com/myapi/posts -X GET
글 목록 보기
[root@zetawiki myapi]# curl http://zetawiki.com/myapi/posts/ -X GET
글 목록 보기
[root@zetawiki myapi]# curl http://zetawiki.com/myapi/posts/ -X POST
새 글 작성하기
[root@zetawiki myapi]# curl http://zetawiki.com/myapi/posts/123 -X GET
[123]번 글 보기
[root@zetawiki myapi]# curl http://zetawiki.com/myapi/posts/123 -X PUT
[123]번 글 수정
[root@zetawiki myapi]# curl http://zetawiki.com/myapi/posts/123 -X DELETE
[123]번 글 삭제
[root@zetawiki myapi]# curl http://zetawiki.com/myapi/posts/123 -X POST
Method Not Allowed

4 같이 보기[ | ]

5 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}