]> Untitled Git - lemmy.git/blob - docs/src/contributing_websocket_http_api.md
Adding version to GetSite. Fixes #1001 (#1002)
[lemmy.git] / docs / src / contributing_websocket_http_api.md
1 # Lemmy API
2
3 *Note: this may lag behind the actual API endpoints [here](../server/src/api). The API should be considered unstable and may change any time.*
4
5 <!-- toc -->
6
7 - [Data types](#data-types)
8 - [Basic usage](#basic-usage)
9   * [WebSocket](#websocket)
10     + [Testing with Websocat](#testing-with-websocat)
11     + [Testing with the WebSocket JavaScript API](#testing-with-the-websocket-javascript-api)
12   * [HTTP](#http)
13     + [Testing with Curl](#testing-with-curl)
14       - [Get Example](#get-example)
15       - [Post Example](#post-example)
16 - [Rate limits](#rate-limits)
17 - [Errors](#errors)
18 - [API documentation](#api-documentation)
19   * [Sort Types](#sort-types)
20   * [Websocket vs HTTP](#websocket-vs-http)
21   * [User / Authentication / Admin actions](#user--authentication--admin-actions)
22     + [Login](#login)
23       - [Request](#request)
24       - [Response](#response)
25       - [HTTP](#http-1)
26     + [Register](#register)
27       - [Request](#request-1)
28       - [Response](#response-1)
29       - [HTTP](#http-2)
30     + [Get User Details](#get-user-details)
31       - [Request](#request-2)
32       - [Response](#response-2)
33       - [HTTP](#http-3)
34     + [Save User Settings](#save-user-settings)
35       - [Request](#request-3)
36       - [Response](#response-3)
37       - [HTTP](#http-4)
38     + [Get Replies / Inbox](#get-replies--inbox)
39       - [Request](#request-4)
40       - [Response](#response-4)
41       - [HTTP](#http-5)
42     + [Get User Mentions](#get-user-mentions)
43       - [Request](#request-5)
44       - [Response](#response-5)
45       - [HTTP](#http-6)
46     + [Edit User Mention](#edit-user-mention)
47       - [Request](#request-6)
48       - [Response](#response-6)
49       - [HTTP](#http-7)
50     + [Mark All As Read](#mark-all-as-read)
51       - [Request](#request-7)
52       - [Response](#response-7)
53       - [HTTP](#http-8)
54     + [Delete Account](#delete-account)
55       - [Request](#request-8)
56       - [Response](#response-8)
57       - [HTTP](#http-9)
58     + [Add admin](#add-admin)
59       - [Request](#request-9)
60       - [Response](#response-9)
61       - [HTTP](#http-10)
62     + [Ban user](#ban-user)
63       - [Request](#request-10)
64       - [Response](#response-10)
65       - [HTTP](#http-11)
66   * [Site](#site)
67     + [List Categories](#list-categories)
68       - [Request](#request-11)
69       - [Response](#response-11)
70       - [HTTP](#http-12)
71     + [Search](#search)
72       - [Request](#request-12)
73       - [Response](#response-12)
74       - [HTTP](#http-13)
75     + [Get Modlog](#get-modlog)
76       - [Request](#request-13)
77       - [Response](#response-13)
78       - [HTTP](#http-14)
79     + [Create Site](#create-site)
80       - [Request](#request-14)
81       - [Response](#response-14)
82       - [HTTP](#http-15)
83     + [Edit Site](#edit-site)
84       - [Request](#request-15)
85       - [Response](#response-15)
86       - [HTTP](#http-16)
87     + [Get Site](#get-site)
88       - [Request](#request-16)
89       - [Response](#response-16)
90       - [HTTP](#http-17)
91     + [Transfer Site](#transfer-site)
92       - [Request](#request-17)
93       - [Response](#response-17)
94       - [HTTP](#http-18)
95     + [Get Site Config](#get-site-config)
96       - [Request](#request-18)
97       - [Response](#response-18)
98       - [HTTP](#http-19)
99     + [Save Site Config](#save-site-config)
100       - [Request](#request-19)
101       - [Response](#response-19)
102       - [HTTP](#http-20)
103   * [Community](#community)
104     + [Get Community](#get-community)
105       - [Request](#request-20)
106       - [Response](#response-20)
107       - [HTTP](#http-21)
108     + [Create Community](#create-community)
109       - [Request](#request-21)
110       - [Response](#response-21)
111       - [HTTP](#http-22)
112     + [List Communities](#list-communities)
113       - [Request](#request-22)
114       - [Response](#response-22)
115       - [HTTP](#http-23)
116     + [Ban from Community](#ban-from-community)
117       - [Request](#request-23)
118       - [Response](#response-23)
119       - [HTTP](#http-24)
120     + [Add Mod to Community](#add-mod-to-community)
121       - [Request](#request-24)
122       - [Response](#response-24)
123       - [HTTP](#http-25)
124     + [Edit Community](#edit-community)
125       - [Request](#request-25)
126       - [Response](#response-25)
127       - [HTTP](#http-26)
128     + [Follow Community](#follow-community)
129       - [Request](#request-26)
130       - [Response](#response-26)
131       - [HTTP](#http-27)
132     + [Get Followed Communities](#get-followed-communities)
133       - [Request](#request-27)
134       - [Response](#response-27)
135       - [HTTP](#http-28)
136     + [Transfer Community](#transfer-community)
137       - [Request](#request-28)
138       - [Response](#response-28)
139       - [HTTP](#http-29)
140   * [Post](#post)
141     + [Create Post](#create-post)
142       - [Request](#request-29)
143       - [Response](#response-29)
144       - [HTTP](#http-30)
145     + [Get Post](#get-post)
146       - [Request](#request-30)
147       - [Response](#response-30)
148       - [HTTP](#http-31)
149     + [Get Posts](#get-posts)
150       - [Request](#request-31)
151       - [Response](#response-31)
152       - [HTTP](#http-32)
153     + [Create Post Like](#create-post-like)
154       - [Request](#request-32)
155       - [Response](#response-32)
156       - [HTTP](#http-33)
157     + [Edit Post](#edit-post)
158       - [Request](#request-33)
159       - [Response](#response-33)
160       - [HTTP](#http-34)
161     + [Save Post](#save-post)
162       - [Request](#request-34)
163       - [Response](#response-34)
164       - [HTTP](#http-35)
165   * [Comment](#comment)
166     + [Create Comment](#create-comment)
167       - [Request](#request-35)
168       - [Response](#response-35)
169       - [HTTP](#http-36)
170     + [Edit Comment](#edit-comment)
171       - [Request](#request-36)
172       - [Response](#response-36)
173       - [HTTP](#http-37)
174     + [Save Comment](#save-comment)
175       - [Request](#request-37)
176       - [Response](#response-37)
177       - [HTTP](#http-38)
178     + [Create Comment Like](#create-comment-like)
179       - [Request](#request-38)
180       - [Response](#response-38)
181       - [HTTP](#http-39)
182   * [RSS / Atom feeds](#rss--atom-feeds)
183     + [All](#all)
184     + [Community](#community-1)
185     + [User](#user)
186
187 <!-- tocstop -->
188
189 ## Data types
190
191 - `i16`, `i32` and `i64` are respectively [16-bit](https://en.wikipedia.org/wiki/16-bit), [32-bit](https://en.wikipedia.org/wiki/32-bit) and [64-bit](https://en.wikipedia.org/wiki/64-bit_computing) integers.
192 - <code>Option<***SomeType***></code> designates an option which may be omitted in requests and not be present in responses. It will be of type ***SomeType***.
193 - <code>Vec<***SomeType***></code> is a list which contains objects of type ***SomeType***.
194 - `chrono::NaiveDateTime` is a timestamp string in [ISO 8601](https://en.wikipedia.org/wiki/ISO_8601) format. Timestamps will be UTC.
195 - Other data types are listed [here](../server/src/db).
196
197 ## Basic usage
198
199 Request and response strings are in [JSON format](https://www.json.org).
200
201 ### WebSocket
202
203 Connect to <code>ws://***host***/api/v1/ws</code> to get started.
204
205 If the ***`host`*** supports secure connections, you can use <code>wss://***host***/api/v1/ws</code>.
206
207 #### Testing with Websocat
208
209 [Websocat link](https://github.com/vi/websocat)
210
211 `websocat ws://127.0.0.1:8536/api/v1/ws -nt`
212
213 A simple test command:
214 `{"op": "ListCategories"}`
215
216 #### Testing with the WebSocket JavaScript API
217
218 [WebSocket JavaScript API](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API)
219 ```javascript
220 var ws = new WebSocket("ws://" + host + "/api/v1/ws");
221 ws.onopen = function () {
222   console.log("Connection succeed!");
223   ws.send(JSON.stringify({
224     op: "ListCategories"
225   }));
226 };
227 ```
228 ### HTTP
229
230 Endpoints are at <code>http://***host***/api/v1/***endpoint***</code>. They'll be listed below for each action.
231
232 #### Testing with Curl
233
234 ##### Get Example
235
236 ```
237 curl /community/list?sort=Hot
238 ```
239
240 ##### Post Example
241
242 ```
243 curl -i -H \
244 "Content-Type: application/json" \
245 -X POST \
246 -d '{
247   "comment_id": X,
248   "post_id": X,
249   "score": X,
250   "auth": "..."
251 }' \
252 /comment/like
253 ```
254
255 ## Rate limits
256
257 - 1 per hour for signups and community creation.
258 - 1 per 10 minutes for post creation.
259 - 30 actions per minute for post voting and comment creation.
260 - Everything else is not rate-limited.
261
262 ## Errors
263 ```rust
264 {
265   op: String,
266   message: String,
267 }
268 ```
269
270 ## API documentation
271
272 ### Sort Types
273
274 These go wherever there is a `sort` field. The available sort types are:
275
276 - `Hot` - the hottest posts/communities, depending on votes, views, comments and publish date
277 - `New` - the newest posts/communities
278 - `TopDay` - the most upvoted posts/communities of the current day.
279 - `TopWeek` - the most upvoted posts/communities of the current week.
280 - `TopMonth` - the most upvoted posts/communities of the current month.
281 - `TopYear` - the most upvoted posts/communities of the current year.
282 - `TopAll` - the most upvoted posts/communities on the current instance.
283
284 ### Websocket vs HTTP
285
286 - Below are the websocket JSON requests / responses. For HTTP, ignore all fields except those inside `data`.
287 - For example, an http login will be a `POST` `{username_or_email: X, password: X}`
288
289 ### User / Authentication / Admin actions
290
291 #### Login
292
293 The `jwt` string should be stored and used anywhere `auth` is called for.
294
295 ##### Request
296 ```rust
297 {
298   op: "Login",
299   data: {
300     username_or_email: String,
301     password: String
302   }
303 }
304 ```
305 ##### Response
306 ```rust
307 {
308   op: "Login",
309   data: {
310     jwt: String,
311   }
312 }
313 ```
314
315 ##### HTTP
316
317 `POST /user/login`
318
319 #### Register
320
321 Only the first user will be able to be the admin.
322
323 ##### Request
324 ```rust
325 {
326   op: "Register",
327   data: {
328     username: String,
329     email: Option<String>,
330     password: String,
331     password_verify: String,
332     admin: bool
333   }
334 }
335 ```
336 ##### Response
337 ```rust
338 {
339   op: "Register",
340   data: {
341     jwt: String,
342   }
343 }
344 ```
345
346 ##### HTTP
347
348 `POST /user/register`
349
350 #### Get User Details
351 ##### Request
352 ```rust
353 {
354   op: "GetUserDetails",
355   data: {
356     user_id: Option<i32>,
357     username: Option<String>,
358     sort: String,
359     page: Option<i64>,
360     limit: Option<i64>,
361     community_id: Option<i32>,
362     saved_only: bool,
363     auth: Option<String>,
364   }
365 }
366 ```
367 ##### Response
368 ```rust
369 {
370   op: "GetUserDetails",
371   data: {
372     user: UserView,
373     follows: Vec<CommunityFollowerView>,
374     moderates: Vec<CommunityModeratorView>,
375     comments: Vec<CommentView>,
376     posts: Vec<PostView>,
377   }
378 }
379 ```
380 ##### HTTP
381
382 `GET /user`
383
384 #### Save User Settings
385 ##### Request
386 ```rust
387 {
388   op: "SaveUserSettings",
389   data: {
390     show_nsfw: bool,
391     theme: String, // Default 'darkly'
392     default_sort_type: i16, // The Sort types from above, zero indexed as a number
393     default_listing_type: i16, // Post listing types are `All, Subscribed, Community`
394     auth: String
395   }
396 }
397 ```
398 ##### Response
399 ```rust
400 {
401   op: "SaveUserSettings",
402   data: {
403     jwt: String
404   }
405 }
406 ```
407 ##### HTTP
408
409 `PUT /save_user_settings`
410
411 #### Get Replies / Inbox
412 ##### Request
413 ```rust
414 {
415   op: "GetReplies",
416   data: {
417     sort: String,
418     page: Option<i64>,
419     limit: Option<i64>,
420     unread_only: bool,
421     auth: String
422   }
423 }
424 ```
425 ##### Response
426 ```rust
427 {
428   op: "GetReplies",
429   data: {
430     replies: Vec<ReplyView>,
431   }
432 }
433 ```
434 ##### HTTP
435
436 `GET /user/replies`
437
438
439 #### Get User Mentions
440 ##### Request
441 ```rust
442 {
443   op: "GetUserMentions",
444   data: {
445     sort: String,
446     page: Option<i64>,
447     limit: Option<i64>,
448     unread_only: bool,
449     auth: String,
450   }
451 }
452 ```
453 ##### Response
454 ```rust
455 {
456   op: "GetUserMentions",
457   data: {
458     mentions: Vec<UserMentionView>,
459   }
460 }
461 ```
462
463 ##### HTTP
464
465 `GET /user/mentions`
466
467 #### Edit User Mention
468 ##### Request
469 ```rust
470 {
471   op: "EditUserMention",
472   data: {
473     user_mention_id: i32,
474     read: Option<bool>,
475     auth: String,
476   }
477 }
478 ```
479 ##### Response
480 ```rust
481 {
482   op: "EditUserMention",
483   data: {
484     mention: UserMentionView,
485   }
486 }
487 ```
488 ##### HTTP
489
490 `PUT /user/mention`
491
492 #### Mark All As Read
493
494 Marks all user replies and mentions as read.
495
496 ##### Request
497 ```rust
498 {
499   op: "MarkAllAsRead",
500   data: {
501     auth: String
502   }
503 }
504 ```
505 ##### Response
506 ```rust
507 {
508   op: "MarkAllAsRead",
509   data: {
510     replies: Vec<ReplyView>,
511   }
512 }
513 ```
514
515 ##### HTTP
516
517 `POST /user/mark_all_as_read`
518
519 #### Delete Account
520
521 *Permananently deletes your posts and comments*
522
523 ##### Request
524 ```rust
525 {
526   op: "DeleteAccount",
527   data: {
528     password: String,
529     auth: String
530   }
531 }
532 ```
533 ##### Response
534 ```rust
535 {
536   op: "DeleteAccount",
537   data: {
538     jwt: String,
539   }
540 }
541 ```
542
543 ##### HTTP
544
545 `POST /user/delete_account`
546
547 #### Add admin
548 ##### Request
549 ```rust
550 {
551   op: "AddAdmin",
552   data: {
553     user_id: i32,
554     added: bool,
555     auth: String
556   }
557 }
558 ```
559 ##### Response
560 ```rust
561 {
562   op: "AddAdmin",
563   data: {
564     admins: Vec<UserView>,
565   }
566 }
567 ```
568 ##### HTTP
569
570 `POST /admin/add`
571
572 #### Ban user
573 ##### Request
574 ```rust
575 {
576   op: "BanUser",
577   data: {
578     user_id: i32,
579     ban: bool,
580     reason: Option<String>,
581     expires: Option<i64>,
582     auth: String
583   }
584 }
585 ```
586 ##### Response
587 ```rust
588 {
589   op: "BanUser",
590   data: {
591     user: UserView,
592     banned: bool,
593   }
594 }
595 ```
596 ##### HTTP
597
598 `POST /user/ban`
599
600 ### Site
601 #### List Categories
602 ##### Request
603 ```rust
604 {
605   op: "ListCategories"
606 }
607 ```
608 ##### Response
609 ```rust
610 {
611   op: "ListCategories",
612   data: {
613     categories: Vec<Category>
614   }
615 }
616 ```
617 ##### HTTP
618
619 `GET /categories`
620
621 #### Search
622
623 Search types are `All, Comments, Posts, Communities, Users, Url`
624
625 ##### Request
626 ```rust
627 {
628   op: "Search",
629   data: {
630     q: String,
631     type_: String,
632     community_id: Option<i32>,
633     sort: String,
634     page: Option<i64>,
635     limit: Option<i64>,
636     auth?: Option<String>,
637   }
638 }
639 ```
640 ##### Response
641 ```rust
642 {
643   op: "Search",
644   data: {
645     type_: String,
646     comments: Vec<CommentView>,
647     posts: Vec<PostView>,
648     communities: Vec<CommunityView>,
649     users: Vec<UserView>,
650   }
651 }
652 ```
653 ##### HTTP
654
655 `POST /search`
656
657 #### Get Modlog
658 ##### Request
659 ```rust
660 {
661   op: "GetModlog",
662   data: {
663     mod_user_id: Option<i32>,
664     community_id: Option<i32>,
665     page: Option<i64>,
666     limit: Option<i64>,
667   }
668 }
669 ```
670 ##### Response
671 ```rust
672 {
673   op: "GetModlog",
674   data: {
675     removed_posts: Vec<ModRemovePostView>,
676     locked_posts: Vec<ModLockPostView>,
677     removed_comments: Vec<ModRemoveCommentView>,
678     removed_communities: Vec<ModRemoveCommunityView>,
679     banned_from_community: Vec<ModBanFromCommunityView>,
680     banned: Vec<ModBanView>,
681     added_to_community: Vec<ModAddCommunityView>,
682     added: Vec<ModAddView>,
683   }
684 }
685 ```
686
687 ##### HTTP
688
689 `GET /modlog`
690
691 #### Create Site
692 ##### Request
693 ```rust
694 {
695   op: "CreateSite",
696   data: {
697     name: String,
698     description: Option<String>,
699     auth: String
700   }
701 }
702 ```
703 ##### Response
704 ```rust
705 {
706   op: "CreateSite",
707     data: {
708     site: SiteView,
709   }
710 }
711 ```
712
713 ##### HTTP
714
715 `POST /site`
716
717 #### Edit Site
718 ##### Request
719 ```rust
720 {
721   op: "EditSite",
722   data: {
723     name: String,
724     description: Option<String>,
725     auth: String
726   }
727 }
728 ```
729 ##### Response
730 ```rust
731 {
732   op: "EditSite",
733   data: {
734     site: SiteView,
735   }
736 }
737 ```
738 ##### HTTP
739
740 `PUT /site`
741
742 #### Get Site
743 ##### Request
744 ```rust
745 {
746   op: "GetSite"
747 }
748 ```
749 ##### Response
750 ```rust
751 {
752   op: "GetSite",
753   data: {
754     site: Option<SiteView>,
755     admins: Vec<UserView>,
756     banned: Vec<UserView>,
757     online: usize, // This is currently broken
758     version: String,
759   }
760 }
761 ```
762 ##### HTTP
763
764 `GET /site`
765
766 #### Transfer Site
767 ##### Request
768 ```rust
769 {
770   op: "TransferSite",
771   data: {
772     user_id: i32,
773     auth: String
774   }
775 }
776 ```
777 ##### Response
778 ```rust
779 {
780   op: "TransferSite",
781   data: {
782     site: Option<SiteView>,
783     admins: Vec<UserView>,
784     banned: Vec<UserView>,
785   }
786 }
787 ```
788 ##### HTTP
789
790 `POST /site/transfer`
791
792 #### Get Site Config
793 ##### Request
794 ```rust
795 {
796   op: "GetSiteConfig",
797   data: {
798     auth: String
799   }
800 }
801 ```
802 ##### Response
803 ```rust
804 {
805   op: "GetSiteConfig",
806   data: {
807     config_hjson: String,
808   }
809 }
810 ```
811 ##### HTTP
812
813 `GET /site/config`
814
815 #### Save Site Config
816 ##### Request
817 ```rust
818 {
819   op: "SaveSiteConfig",
820   data: {
821     config_hjson: String,
822     auth: String
823   }
824 }
825 ```
826 ##### Response
827 ```rust
828 {
829   op: "SaveSiteConfig",
830   data: {
831     config_hjson: String,
832   }
833 }
834 ```
835 ##### HTTP
836
837 `PUT /site/config`
838
839 ### Community
840 #### Get Community
841 ##### Request
842 ```rust
843 {
844   op: "GetCommunity",
845   data: {
846     id: Option<i32>,
847     name: Option<String>,
848     auth: Option<String>
849   }
850 }
851 ```
852 ##### Response
853 ```rust
854 {
855   op: "GetCommunity",
856   data: {
857     community: CommunityView,
858     moderators: Vec<CommunityModeratorView>,
859     admins: Vec<UserView>,
860   }
861 }
862 ```
863 ##### HTTP
864
865 `GET /community`
866
867 #### Create Community
868 ##### Request
869 ```rust
870 {
871   op: "CreateCommunity",
872   data: {
873     name: String,
874     title: String,
875     description: Option<String>,
876     category_id: i32 ,
877     auth: String
878   }
879 }
880 ```
881 ##### Response
882 ```rust
883 {
884   op: "CreateCommunity",
885   data: {
886     community: CommunityView
887   }
888 }
889 ```
890 ##### HTTP
891
892 `POST /community`
893
894 #### List Communities
895 ##### Request
896 ```rust
897 {
898   op: "ListCommunities",
899   data: {
900     sort: String,
901     page: Option<i64>,
902     limit: Option<i64>,
903     auth: Option<String>
904   }
905 }
906 ```
907 ##### Response
908 ```rust
909 {
910   op: "ListCommunities",
911   data: {
912     communities: Vec<CommunityView>
913   }
914 }
915 ```
916 ##### HTTP
917
918 `GET /community/list`
919
920 #### Ban from Community
921 ##### Request
922 ```rust
923 {
924   op: "BanFromCommunity",
925   data: {
926     community_id: i32,
927     user_id: i32,
928     ban: bool,
929     reason: Option<String>,
930     expires: Option<i64>,
931     auth: String
932   }
933 }
934 ```
935 ##### Response
936 ```rust
937 {
938   op: "BanFromCommunity",
939   data: {
940     user: UserView,
941     banned: bool,
942   }
943 }
944 ```
945 ##### HTTP
946
947 `POST /community/ban_user`
948
949 #### Add Mod to Community
950 ##### Request
951 ```rust
952 {
953   op: "AddModToCommunity",
954   data: {
955     community_id: i32,
956     user_id: i32,
957     added: bool,
958     auth: String
959   }
960 }
961 ```
962 ##### Response
963 ```rust
964 {
965   op: "AddModToCommunity",
966   data: {
967     moderators: Vec<CommunityModeratorView>,
968   }
969 }
970 ```
971 ##### HTTP
972
973 `POST /community/mod`
974
975 #### Edit Community
976 Mods and admins can remove and lock a community, creators can delete it.
977
978 ##### Request
979 ```rust
980 {
981   op: "EditCommunity",
982   data: {
983     edit_id: i32,
984     title: String,
985     description: Option<String>,
986     category_id: i32,
987     removed: Option<bool>,
988     deleted: Option<bool>,
989     reason: Option<String>,
990     expires: Option<i64>,
991     auth: String
992   }
993 }
994 ```
995 ##### Response
996 ```rust
997 {
998   op: "EditCommunity",
999   data: {
1000     community: CommunityView
1001   }
1002 }
1003 ```
1004 ##### HTTP
1005
1006 `PUT /community`
1007
1008 #### Follow Community
1009 ##### Request
1010 ```rust
1011 {
1012   op: "FollowCommunity",
1013   data: {
1014     community_id: i32,
1015     follow: bool,
1016     auth: String
1017   }
1018 }
1019 ```
1020 ##### Response
1021 ```rust
1022 {
1023   op: "FollowCommunity",
1024   data: {
1025     community: CommunityView
1026   }
1027 }
1028 ```
1029 ##### HTTP
1030
1031 `POST /community/follow`
1032
1033 #### Get Followed Communities
1034 ##### Request
1035 ```rust
1036 {
1037   op: "GetFollowedCommunities",
1038   data: {
1039     auth: String
1040   }
1041 }
1042 ```
1043 ##### Response
1044 ```rust
1045 {
1046   op: "GetFollowedCommunities",
1047   data: {
1048     communities: Vec<CommunityFollowerView>
1049   }
1050 }
1051 ```
1052 ##### HTTP
1053
1054 `GET /user/followed_communities`
1055
1056 #### Transfer Community
1057 ##### Request
1058 ```rust
1059 {
1060   op: "TransferCommunity",
1061   data: {
1062     community_id: i32,
1063     user_id: i32,
1064     auth: String
1065   }
1066 }
1067 ```
1068 ##### Response
1069 ```rust
1070 {
1071   op: "TransferCommunity",
1072   data: {
1073     community: CommunityView,
1074     moderators: Vec<CommunityModeratorView>,
1075     admins: Vec<UserView>,
1076   }
1077 }
1078 ```
1079 ##### HTTP
1080
1081 `POST /community/transfer`
1082
1083 ### Post
1084 #### Create Post
1085 ##### Request
1086 ```rust
1087 {
1088   op: "CreatePost",
1089   data: {
1090     name: String,
1091     url: Option<String>,
1092     body: Option<String>,
1093     community_id: i32,
1094     auth: String
1095   }
1096 }
1097 ```
1098 ##### Response
1099 ```rust
1100 {
1101   op: "CreatePost",
1102   data: {
1103     post: PostView
1104   }
1105 }
1106 ```
1107 ##### HTTP
1108
1109 `POST /post`
1110
1111 #### Get Post
1112 ##### Request
1113 ```rust
1114 {
1115   op: "GetPost",
1116   data: {
1117     id: i32,
1118     auth: Option<String>
1119   }
1120 }
1121 ```
1122 ##### Response
1123 ```rust
1124 {
1125   op: "GetPost",
1126   data: {
1127     post: PostView,
1128     comments: Vec<CommentView>,
1129     community: CommunityView,
1130     moderators: Vec<CommunityModeratorView>,
1131     admins: Vec<UserView>,
1132   }
1133 }
1134 ```
1135 ##### HTTP
1136
1137 `GET /post`
1138
1139 #### Get Posts
1140
1141 Post listing types are `All, Subscribed, Community`
1142
1143 ##### Request
1144 ```rust
1145 {
1146   op: "GetPosts",
1147   data: {
1148     type_: String,
1149     sort: String,
1150     page: Option<i64>,
1151     limit: Option<i64>,
1152     community_id: Option<i32>,
1153     community_name: Option<String>,
1154     auth: Option<String>
1155   }
1156 }
1157 ```
1158 ##### Response
1159 ```rust
1160 {
1161   op: "GetPosts",
1162   data: {
1163     posts: Vec<PostView>,
1164   }
1165 }
1166 ```
1167 ##### HTTP
1168
1169 `GET /post/list`
1170
1171 #### Create Post Like
1172
1173 `score` can be 0, -1, or 1
1174
1175 ##### Request
1176 ```rust
1177 {
1178   op: "CreatePostLike",
1179   data: {
1180     post_id: i32,
1181     score: i16,
1182     auth: String
1183   }
1184 }
1185 ```
1186 ##### Response
1187 ```rust
1188 {
1189   op: "CreatePostLike",
1190   data: {
1191     post: PostView
1192   }
1193 }
1194 ```
1195 ##### HTTP
1196
1197 `POST /post/like`
1198
1199 #### Edit Post
1200
1201 Mods and admins can remove and lock a post, creators can delete it.
1202
1203 ##### Request
1204 ```rust
1205 {
1206   op: "EditPost",
1207   data: {
1208     edit_id: i32,
1209     creator_id: i32,
1210     community_id: i32,
1211     name: String,
1212     url: Option<String>,
1213     body: Option<String>,
1214     removed: Option<bool>,
1215     deleted: Option<bool>,
1216     locked: Option<bool>,
1217     reason: Option<String>,
1218     auth: String
1219   }
1220 }
1221 ```
1222 ##### Response
1223 ```rust
1224 {
1225   op: "EditPost",
1226   data: {
1227     post: PostView
1228   }
1229 }
1230 ```
1231
1232 ##### HTTP
1233
1234 `PUT /post`
1235
1236 #### Save Post
1237 ##### Request
1238 ```rust
1239 {
1240   op: "SavePost",
1241   data: {
1242     post_id: i32,
1243     save: bool,
1244     auth: String
1245   }
1246 }
1247 ```
1248 ##### Response
1249 ```rust
1250 {
1251   op: "SavePost",
1252   data: {
1253     post: PostView
1254   }
1255 }
1256 ```
1257 ##### HTTP
1258
1259 `POST /post/save`
1260
1261 ### Comment
1262 #### Create Comment
1263 ##### Request
1264 ```rust
1265 {
1266   op: "CreateComment",
1267   data: {
1268     content: String,
1269     parent_id: Option<i32>,
1270     edit_id: Option<i32>,
1271     post_id: i32,
1272     auth: String
1273   }
1274 }
1275 ```
1276 ##### Response
1277 ```rust
1278 {
1279   op: "CreateComment",
1280   data: {
1281     comment: CommentView
1282   }
1283 }
1284 ```
1285
1286 ##### HTTP
1287
1288 `POST /comment`
1289
1290 #### Edit Comment
1291
1292 Mods and admins can remove a comment, creators can delete it.
1293
1294 ##### Request
1295 ```rust
1296 {
1297   op: "EditComment",
1298   data: {
1299     content: String,
1300     parent_id: Option<i32>,
1301     edit_id: i32,
1302     creator_id: i32,
1303     post_id: i32,
1304     removed: Option<bool>,
1305     deleted: Option<bool>,
1306     reason: Option<String>,
1307     read: Option<bool>,
1308     auth: String
1309   }
1310 }
1311 ```
1312 ##### Response
1313 ```rust
1314 {
1315   op: "EditComment",
1316   data: {
1317     comment: CommentView
1318   }
1319 }
1320 ```
1321 ##### HTTP
1322
1323 `PUT /comment`
1324
1325 #### Save Comment
1326 ##### Request
1327 ```rust
1328 {
1329   op: "SaveComment",
1330   data: {
1331     comment_id: i32,
1332     save: bool,
1333     auth: String
1334   }
1335 }
1336 ```
1337 ##### Response
1338 ```rust
1339 {
1340   op: "SaveComment",
1341   data: {
1342     comment: CommentView
1343   }
1344 }
1345 ```
1346 ##### HTTP
1347
1348 `POST /comment/save`
1349
1350 #### Create Comment Like
1351
1352 `score` can be 0, -1, or 1
1353
1354 ##### Request
1355 ```rust
1356 {
1357   op: "CreateCommentLike",
1358   data: {
1359     comment_id: i32,
1360     post_id: i32,
1361     score: i16,
1362     auth: String
1363   }
1364 }
1365 ```
1366 ##### Response
1367 ```rust
1368 {
1369   op: "CreateCommentLike",
1370   data: {
1371     comment: CommentView
1372   }
1373 }
1374 ```
1375 ##### HTTP
1376
1377 `POST /comment/like`
1378
1379 ### RSS / Atom feeds
1380
1381 #### All
1382
1383 `/feeds/all.xml?sort=Hot`
1384
1385 #### Community
1386
1387 `/feeds/c/community-name.xml?sort=Hot`
1388
1389 #### User
1390
1391 `/feeds/u/user-name.xml?sort=Hot`
1392