我已经为我的Rails应用程序编写了一个API,它现在执行以下操作。
1.使用电子邮件和密码登录。返回用户的访问令牌。
$ curl -i -H "Accept: application/json" -H "Content-type: application/json" -X POST -d '{"user":{"email":"testtesttest@test.com", "password":"testtest"}}' 'http://rails-tutorial-sumai.c9.io/api/sessions'
HTTP/1.1 200 OK
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
content-type: application/json; charset=utf-8
etag: W/"dab624d9e5b16d1dd447605c6d0dfde9"
cache-control: max-age=0, private, must-revalidate
x-request-id: 36d360e0-765f-410c-b962-d0780f1e5eab
x-runtime: 0.097109
transfer-encoding: chunked
server: WEBrick/1.3.1 (Ruby/2.1.4/2014-10-27)
date: Tue, 21 Apr 2015 23:50:24 GMT
{"id":2,"access_token":"6148e8897c25b8b16ab5b938b5e481d3bb7faf825613a5fa","user_id":14,"created_at":"2015-04-21T22:42:51.656Z","updated_at":"2015-04-21T22:42:51.656Z"}
$
2.使用访问令牌显示所有用户。
$ curl -H 'Authorization: Token token="6148e8897c25b8b16ab5b938b5e481d3bb7faf825613a5fa"' -i 'http://rails-tutorial-sumai.c9.io/api/users'
HTTP/1.1 200 OK
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
content-type: application/json; charset=utf-8
etag: W/"bfc3aeabca5e1f1d8deaa9f9bcb1b557"
cache-control: max-age=0, private, must-revalidate
x-request-id: e46ed53b-9987-4ad4-b7d6-a1ef6d00fd14
x-runtime: 0.029815
transfer-encoding: chunked
server: WEBrick/1.3.1 (Ruby/2.1.4/2014-10-27)
date: Tue, 21 Apr 2015 23:50:30 GMT
[{"id":14,"name":"testtest","email":"testtesttest@test.com","created_at":"2015-04-21T22:21:36.268Z","updated_at":"2015-04-21T22:34:32.548Z","password_digest":"$2a$10$dv3LVipJCyy/O8mIufjrMuWa0YBmL68BWOJciY27Uzz9euBILtJUO","remember_digest":null,"admin":false,"date_of_birth":"1985-01-01T00:00:00.000Z","is_female":true,"activation_digest":"$2a$10$1i3gmOM93MKaZ4.xMmydjOVqlYBSqecfZMyORQvM93C3.rrpK4Wgu","activated":true,"activated_at":"2015-04-21T22:24:36.507Z","reset_digest":null,"reset_sent_at":null,"avatar_file_name":null,"avatar_content_type":null,"avatar_file_size":null,"avatar_updated_at":null,"country_id":5,"cover_file_name":null,"cover_content_type":null,"cover_file_size":null,"cover_updated_at":null,"intro":"hehe"},{"id":1,"name":"sumar","email":"chu07@gmail.com","created_at":"2015-01-23T12:57:41.502Z","updated_at":"2015-03-28T02:53:46.438Z","password_digest":"$2a$10$xNvGKpPwspaeTd33QrTwuuLP0TesuuTmfbrUlFO7LDsWXGkf7XP7m","remember_digest":null,"admin":false,"date_of_birth":"1985-01-01T00:00:00.000Z","is_female":true,"activation_digest":"$2a$10$nIwWkX2X8WugscC/Yre7KeWRIzw6ecNyA5hLn/xPw9C0FyzyO6BJq","activated":true,"activated_at":"2015-01-23T12:58:58.337Z","reset_digest":null,"reset_sent_at":null,"avatar_file_name":null,"avatar_content_type":null,"avatar_file_size":null,"avatar_updated_at":null,"country_id":1,"cover_file_name":null,"cover_content_type":null,"cover_file_size":null,"cover_updated_at":null,"intro":"test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test "},{"id":13,"name":"mah kumar","email":"testlmah@gmail.com","created_at":"2015-03-24T13:57:56.184Z","updated_at":"2015-03-24T13:58:47.267Z","password_digest":"$2a$10$oyIFQ9b.yyLQ8AMagwGNfeBE9.iXhSg/8PyoQ8fO9.ApH3ZvZ7Q/K","remember_digest":null,"admin":false,"date_of_birth":"1985-01-01T00:00:00.000Z","is_female":false,"activation_digest":"$2a$10$xhpJCNVDvyLqcBZC8LhgkOqTeptHEy.UGNCH.4FFGBLPalLotqPQO","activated":true,"activated_at":"2015-03-24T13:58:23.488Z","reset_digest":null,"reset_sent_at":null,"avatar_file_name":null,"avatar_content_type":null,"avatar_file_size":null,"avatar_updated_at":null,"country_id":1,"cover_file_name":null,"cover_content_type":null,"cover_file_size":null,"cover_updated_at":null,"intro":"test"},{"id":12,"name":"intro kumar","email":"chutest@gmail.com","created_at":"2015-03-24T13:39:40.659Z","updated_at":"2015-03-24T13:51:20.796Z","password_digest":"$2a$10$2bchzMYDDCXcDKdGS7NmceOH0700NAWQnVwjr3JDSF4duPmIFtFPi","remember_digest":null,"admin":false,"date_of_birth":"1985-01-01T00:00:00.000Z","is_female":false,"activation_digest":"$2a$10$VDWd7wNBHbdsD7j2k1gpa.UAGcXXcibVlUYsMCPd9CJu5es6vTnDK","activated":true,"activated_at":"2015-03-24T13:40:00.180Z","reset_digest":null,"reset_sent_at":null,"avatar_file_name":null,"avatar_content_type":null,"avatar_file_size":null,"avatar_updated_at":null,"country_id":1,"cover_file_name":null,"cover_content_type":null,"cover_file_size":null,"cover_updated_at":null,"intro":"test"},{"id":11,"name":"testingkumar","email":"testlama@gmail.com","created_at":"2015-03-24T13:23:11.249Z","updated_at":"2015-03-24T13:32:03.393Z","password_digest":"$2a$10$SAJJ4nF/uKiYHJfWmNjRG.DWbGctI4YXW3j/lfq3fFwQd3MdFU5ei","remember_digest":null,"admin":false,"date_of_birth":"1985-01-01T00:00:00.000Z","is_female":false,"activation_digest":"$2a$10$LAcveGkYgUDGd6kyCq2T4.ZaMDhcu1rT7YnZFcMeqf..fB22oonhm","activated":true,"activated_at":"2015-03-24T13:23:24.477Z","reset_digest":null,"reset_sent_at":null,"avatar_file_name":null,"avatar_content_type":null,"avatar_file_size":null,"avatar_updated_at":null,"country_id":1,"cover_file_name":null,"cover_content_type":null,"cover_file_size":null,"cover_updated_at":null,"intro":"test"},{"id":10,"name":"Test kumar","email":"testkumar@gmail.com","created_at":"2015-03-24T08:00:49.896Z","updated_at":"2015-03-24T13:14:31.973Z","password_digest":"$2a$10$2CePnBtr1C2IjDGaK3USFe06JY437g2cAAKLShO4Zw9nWqA3Xdnve","remember_digest":null,"admin":false,"date_of_birth":"1985-01-01T00:00:00.000Z","is_female":false,"activation_digest":"$2a$10$AdvDADJ78vC0/NMysfckxeTJOGc2rxwcw2n653ySeEmlue1v2ZRbW","activated":true,"activated_at":"2015-03-24T08:01:20.566Z","reset_digest":null,"reset_sent_at":null,"avatar_file_name":null,"avatar_content_type":null,"avatar_file_size":null,"avatar_updated_at":null,"country_id":1,"cover_file_name":null,"cover_content_type":null,"cover_file_size":null,"cover_updated_at":null,"intro":"test"},{"id":9,"name":"Karesh Kumar","email":"test5@test5.com","created_at":"2015-03-08T20:02:48.369Z","updated_at":"2015-03-08T20:05:46.148Z","password_digest":"$2a$10$6iTjYf.07juB92ha0UCUn.jpUWca.y.VTDRZQ3H1s1pspVvArBFw6","remember_digest":null,"admin":false,"date_of_birth":"1985-01-01T00:00:00.000Z","is_female":false,"activation_digest":"$2a$10$DhyOJ86NqhCly8GfnM44/OPN78mlgGxqXQ29CGvoaYR7xCO5EE68y","activated":true,"activated_at":"2015-03-08T20:03:16.968Z","reset_digest":"$2a$10$wNXmFgm8BECjybD8eE4D7eYyGioHIt/qBVmBwQ7SrRpOKn4/yOTw2","reset_sent_at":"2015-03-08T20:04:44.748Z","avatar_file_name":null,"avatar_content_type":null,"avatar_file_size":null,"avatar_updated_at":null,"country_id":1,"cover_file_name":null,"cover_content_type":null,"cover_file_size":null,"cover_updated_at":null,"intro":"hey"},{"id":5,"name":"testtest","email":"test1@test1.com","created_at":"2015-03-08T19:46:06.830Z","updated_at":"2015-03-08T19:47:30.477Z","password_digest":"$2a$10$2aiBrrVNUjBAXICo6tNTU./O.p18/4RQ1gKU22f2/A3I1t6y0byNq","remember_digest":null,"admin":false,"date_of_birth":"1985-01-01T00:00:00.000Z","is_female":false,"activation_digest":"$2a$10$R1KDahoJDTJqdd6ND0FO8eDCOYzR4Qk1tffifm5qFpTfr7wcGF2bi","activated":true,"activated_at":"2015-03-08T19:46:32.225Z","reset_digest":null,"reset_sent_at":null,"avatar_file_name":null,"avatar_content_type":null,"avatar_file_size":null,"avatar_updated_at":null,"country_id":1,"cover_file_name":null,"cover_content_type":null,"cover_file_size":null,"cover_updated_at":null,"intro":"testtest"},{"id":4,"name":"Mahesh Kumar","email":"testing@test.com","created_at":"2015-02-16T14:32:41.566Z","updated_at":"2015-02-16T14:33:56.728Z","password_digest":"$2a$10$kwjZJVg5EDC52L6aeZeV8urOU/.mlL6ZAGK.CR5acNpjm3SvAcr9y","remember_digest":null,"admin":false,"date_of_birth":"1978-05-10T00:00:00.000Z","is_female":true,"activation_digest":"$2a$10$xOS01HD6vICt2PWrDtJhYOwXissxrbtD4h9kqNr2AfBss.EzsSzC.","activated":true,"activated_at":"2015-02-16T14:33:18.257Z","reset_digest":null,"reset_sent_at":null,"avatar_file_name":null,"avatar_content_type":null,"avatar_file_size":null,"avatar_updated_at":null,"country_id":12,"cover_file_name":null,"cover_content_type":null,"cover_file_size":null,"cover_updated_at":null,"intro":"test"}]
$
3.使用access_token
显示单个用户$ curl -H 'Authorization: Token token="6148e8897c25b8b16ab5b938b5e481d3bb7faf825613a5fa"' -i 'http://rails-tutorial-sumai.c9.io/api/users/12'
HTTP/1.1 200 OK
x-xss-protection: 1; mode=block
x-content-type-options: nosniff
content-type: application/json; charset=utf-8
etag: W/"0c556c7850e78074ec37aa308526595d"
cache-control: max-age=0, private, must-revalidate
x-request-id: 4157a358-fd0d-4603-a699-2918793da586
x-runtime: 0.053024
transfer-encoding: chunked
server: WEBrick/1.3.1 (Ruby/2.1.4/2014-10-27)
date: Tue, 21 Apr 2015 23:50:41 GMT
{"id":12,"name":"intro kumar","email":"chutest@gmail.com","created_at":"2015-03-24T13:39:40.659Z","updated_at":"2015-03-24T13:51:20.796Z","password_digest":"$2a$10$2bchzMYDDCXcDKdGS7NmceOH0700NAWQnVwjr3JDSF4duPmIFtFPi","remember_digest":null,"admin":false,"date_of_birth":"1985-01-01T00:00:00.000Z","is_female":false,"activation_digest":"$2a$10$VDWd7wNBHbdsD7j2k1gpa.UAGcXXcibVlUYsMCPd9CJu5es6vTnDK","activated":true,"activated_at":"2015-03-24T13:40:00.180Z","reset_digest":null,"reset_sent_at":null,"avatar_file_name":null,"avatar_content_type":null,"avatar_file_size":null,"avatar_updated_at":null,"country_id":1,"cover_file_name":null,"cover_content_type":null,"cover_file_size":null,"cover_updated_at":null,"intro":"test","microposts":[]}
$
我是Android编程的新手。我已经使用Android studio创建了一个非常简单的Android应用程序,只需按照某些在线教程即可查看textview和按钮 现在我想创建一个登录页面,并使用我为rails应用程序创建的API显示所有用户。
有人可以指向可帮助我登录然后显示所有用户的资源吗? 感谢。