Seaside-REST APIs for RedditSt20

I’ve implemented RESTful APIs for RedditSt20 using Seaside-REST. The API endpoints are accessible using Curl:

% curl -X GET -H "Accept: text/json" http://127.0.0.1:8080/redditst20-api/latestLinks

The same from Zinc, using NeoJSON to pretty-print:

NeoJSONWriter toStringPretty: 
  (NeoJSONObject fromString: 
    (ZnEasy get: 'http://127.0.0.1:8080/redditst20-api/latestLinks') contents)

Output:

[
	{
		"points" : 0,
		"url" : "http://postgresql.org",
		"created" : "2018-01-13T20:03:56.405254+08:00",
		"title" : "PostgreSQL",
		"id" : 9
	},
	{
		"points" : 0,
		"url" : "http://sqlite.org",
		"created" : "2018-01-13T20:03:56.404526+08:00",
		"title" : "SQLite",
		"id" : 10
	},
	{
		"points" : 0,
		"url" : "http://pharo.org",
		"created" : "2018-01-13T20:03:56.403656+08:00",
		"title" : "Pharo",
		"id" : 11
	}
]

Voting is implemented using POST:

% curl -X POST 
    -H "Accept: text/json" 
    -H "Content-Type: text/json" 
    http://127.0.0.1:8080/redditst20-api/11/voteUp  
{"Updated":"true"}
%

Let’s check out the highest ranking links:

NeoJSONWriter toStringPretty: 
  (NeoJSONObject fromString: 
    (ZnEasy get: 'http://127.0.0.1:8080/redditst20-api/highestRankingLinks') contents)

Here’s the output:

[
	{
		"points" : 1,
		"url" : "http://pharo.org",
		"created" : "2018-01-13T20:03:56.403656+08:00",
		"title" : "Pharo",
		"id" : 11
	},
	{
		"points" : 0,
		"url" : "http://postgresql.org",
		"created" : "2018-01-13T20:03:56.405254+08:00",
		"title" : "PostgreSQL",
		"id" : 9
	},
	{
		"points" : 0,
		"url" : "http://sqlite.org",
		"created" : "2018-01-13T20:03:56.404526+08:00",
		"title" : "SQLite",
		"id" : 10
	}
]

To create a new link, use PUT:

% curl -X PUT 
    -H "Accept: text/json" 
    -H "Content-Type: text/json" 
    -d '{"title":"Glorp", "url":"http://glorp.org"}' 
    http://127.0.0.1:8080/redditst20-api/putLink   
{"Created":true}
%

And here it is:

[
	{
		"points" : 0,
		"url" : "http://glorp.org",
		"created" : "2018-01-13T20:15:15.569197+08:00",
		"title" : "Glorp",
		"id" : 12
	},
        ... 
]

Code is on STH
. I plan to move it to GH anytime now.

Tags:Seaside.

稿源:samadhiweb (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 后端存储 » Seaside-REST APIs for RedditSt20

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录