-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
171 additions
and
74 deletions.
There are no files selected for viewing
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
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
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
30 changes: 0 additions & 30 deletions
30
samples/http_rest/src/main/scala/code/lib/DependencyFactory.scala
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package code | ||
package lib | ||
|
||
import model._ | ||
|
||
import net.liftweb._ | ||
import common._ | ||
import http._ | ||
import rest._ | ||
import json._ | ||
import scala.xml._ | ||
|
||
/** | ||
* A full REST example | ||
*/ | ||
object FullRest extends RestHelper { | ||
|
||
// Serve /api/item and friends | ||
serve( "api" / "item" prefix { | ||
|
||
// /api/item returns all the items | ||
case Nil JsonGet _ => Item.inventoryItems: JValue | ||
|
||
// /api/item/count gets the item count | ||
case "count" :: Nil JsonGet _ => JInt(Item.inventoryItems.length) | ||
|
||
// /api/item/item_id gets the specified item (or a 404) | ||
case Item(item) :: Nil JsonGet _ => item: JValue | ||
|
||
// /api/item/search/foo or /api/item/search?q=foo | ||
case "search" :: q JsonGet _ => | ||
(for { | ||
searchString <- q ::: S.params("q") | ||
item <- Item.search(searchString) | ||
} yield item).distinct: JValue | ||
|
||
// DELETE the item in question | ||
case Item(item) :: Nil JsonDelete _ => | ||
Item.delete(item.id).map(a => a: JValue) | ||
|
||
// PUT adds the item if the JSON is parsable | ||
case Nil JsonPut Item(item) -> _ => Item.add(item): JValue | ||
|
||
// POST if we find the item, merge the fields from the | ||
// the POST body and update the item | ||
case Item(item) :: Nil JsonPost json -> _ => | ||
Item(mergeJson(item, json)).map(Item.add(_): JValue) | ||
}) | ||
} |
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
16 changes: 0 additions & 16 deletions
16
samples/http_rest/src/main/scala/code/snippet/HelloWorld.scala
This file was deleted.
Oops, something went wrong.