Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
R
restable
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
CI / CD
CI / CD
Pipelines
Schedules
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
terranet
restable
Commits
6871ad23
Commit
6871ad23
authored
Mar 05, 2015
by
endi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update Readme.md
parent
e865fb96
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
56 deletions
+24
-56
README.md
README.md
+24
-56
No files found.
README.md
View file @
6871ad23
## RESTful format response for Laravel
### For Laravel 4, please use the [v1.x branch](https://github.com/teepluss/laravel-restable/tree/v1.x)!
Restable is a useful to create RESTful API response format that support multiple format, such as Json, XML
Serialized, PHP.
### Installation
-
[
Restable on Packagist
](
https://packagist.org/packages/teepluss/restable
)
-
[
Restable on GitHub
](
https://github.com/teepluss/laravel-restable
)
To get the lastest version of Theme simply require it in your
`composer.json`
file.
~~~
"te
epluss
/restable": "dev-master"
"te
rranet
/restable": "dev-master"
~~~
You'll then need to run
`composer install`
to download it and have the autoloader updated.
Once
Them
e is installed you need to register the service provider with the application. Open up
`config/app.php`
and find the
`providers`
key.
Once
Packag
e is installed you need to register the service provider with the application. Open up
`config/app.php`
and find the
`providers`
key.
~~~
'providers' => array(
'Te
epluss
\Restable\RestableServiceProvider'
'Te
rranet
\Restable\RestableServiceProvider'
)
~~~
...
...
@@ -33,7 +28,7 @@ Restable also ships with a facade which provides the static syntax for creating
~~~
'aliases' => array(
'Restable' => 'Te
epluss
\Restable\Facades\Restable'
'Restable' => 'Te
rranet
\Restable\Facades\Restable'
)
~~~
...
...
@@ -61,7 +56,7 @@ class ApiBlogsController extends BaseController {
{
if
(
!
Input
::
get
(
'secret'
)
==
'12345'
)
{
return
Restable
::
unauthorized
()
->
render
()
;
return
Restable
::
unauthorized
();
}
}
...
...
@@ -79,7 +74,7 @@ class ApiBlogsController extends BaseController {
//return Restable::listing(Blog::paginate())->to('xml');
//return Restable::listing(Blog::paginate())->toXML();
return
Restable
::
listing
(
Blog
::
paginate
())
->
render
()
;
return
Restable
::
listing
(
Blog
::
paginate
());
}
/**
...
...
@@ -108,7 +103,7 @@ class ApiBlogsController extends BaseController {
if
(
$validator
->
fails
())
{
return
Restable
::
unprocess
(
$validator
)
->
render
()
;
return
Restable
::
unprocess
(
$validator
);
}
$blog
->
title
=
Input
::
get
(
'title'
);
...
...
@@ -116,7 +111,7 @@ class ApiBlogsController extends BaseController {
$blog
->
save
();
return
Restable
::
created
(
$blog
)
->
render
()
;
return
Restable
::
created
(
$blog
);
}
/**
...
...
@@ -131,10 +126,10 @@ class ApiBlogsController extends BaseController {
if
(
!
$blog
)
{
return
Restable
::
missing
()
->
render
();
return
Restable
::
missing
()
}
return
Restable
::
single
(
$blog
)
->
render
()
;
return
Restable
::
single
(
$blog
);
}
/**
...
...
@@ -149,7 +144,7 @@ class ApiBlogsController extends BaseController {
if
(
!
$blog
)
{
return
Restable
::
missing
()
->
render
()
;
return
Restable
::
missing
();
}
return
View
::
make
(
'api.blogs.edit'
,
compact
(
'blog'
));
...
...
@@ -167,7 +162,7 @@ class ApiBlogsController extends BaseController {
if
(
!
$blog
)
{
return
Restable
::
missing
()
->
render
()
;
return
Restable
::
missing
();
}
$validator
=
Validator
::
make
(
Input
::
all
(),
array
(
...
...
@@ -177,7 +172,7 @@ class ApiBlogsController extends BaseController {
if
(
$validator
->
fails
())
{
return
Restable
::
unprocess
(
$validator
)
->
render
()
;
return
Restable
::
unprocess
(
$validator
);
}
$blog
->
title
=
Input
::
get
(
'title'
);
...
...
@@ -185,7 +180,7 @@ class ApiBlogsController extends BaseController {
$blog
->
save
();
return
Restable
::
updated
(
$blog
)
->
render
()
;
return
Restable
::
updated
(
$blog
);
}
/**
...
...
@@ -200,12 +195,12 @@ class ApiBlogsController extends BaseController {
if
(
!
$blog
)
{
return
Restable
::
missing
()
->
render
()
;
return
Restable
::
missing
();
}
$blog
->
delete
();
return
Restable
::
deleted
()
->
render
()
;
return
Restable
::
deleted
();
}
}
...
...
@@ -214,54 +209,27 @@ class ApiBlogsController extends BaseController {
Error cases.
~~~
php
// Unauthorized.
Restable
::
unauthorized
()
->
render
()
;
Restable
::
unauthorized
();
// Bad request.
Restable
::
bad
()
->
render
()
;
Restable
::
bad
();
// Missing, Not found.
Restable
::
missing
()
->
render
()
;
Restable
::
missing
();
// Unprocess, Validation Failed.
Restable
::
unprocess
()
->
render
()
;
Restable
::
unprocess
();
// Custom.
Restable
::
error
(
null
,
429
)
->
render
()
;
Restable
::
error
(
null
,
429
);
~~~
Another success cases.
~~~
php
return
Restable
::
success
()
->
render
()
;
return
Restable
::
success
();
~~~
Changing error code.
~~~
php
return
Restable
::
code
(
9001
)
->
bad
(
'message'
)
->
render
()
;
return
Restable
::
code
(
9001
)
->
bad
(
'message'
);
~~~
\ No newline at end of file
Render to another format.
~~~
php
// XML
return
Restable
::
single
(
$data
)
->
render
(
'xml'
);
// Serialized
return
Restable
::
single
(
$data
)
->
render
(
'serialized'
);
// PHP
return
Restable
::
single
(
$data
)
->
render
(
'php'
);
// JSON
return
Restable
::
single
(
$data
)
->
render
(
'json'
);
// JSONP
return
Restable
::
single
(
$data
)
->
render
(
'json'
,
Input
::
get
(
'callback'
));
// OR
return
Restable
::
single
(
$data
)
->
toJson
(
Input
::
get
(
'callback'
));
~~~
## Support or Contact
If you have some problem, Contact teepluss@gmail.com
[

](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=9GEC8J7FAG6JA)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment