api.go 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2018 Frédéric Guillot. All rights reserved.
  2. // Use of this source code is governed by the Apache 2.0
  3. // license that can be found in the LICENSE file.
  4. package api // import "miniflux.app/api"
  5. import (
  6. "net/http"
  7. "miniflux.app/storage"
  8. "miniflux.app/worker"
  9. "github.com/gorilla/mux"
  10. )
  11. type handler struct {
  12. store *storage.Storage
  13. pool *worker.Pool
  14. }
  15. // Serve declares API routes for the application.
  16. func Serve(router *mux.Router, store *storage.Storage, pool *worker.Pool) {
  17. handler := &handler{store, pool}
  18. sr := router.PathPrefix("/v1").Subrouter()
  19. middleware := newMiddleware(store)
  20. sr.Use(middleware.handleCORS)
  21. sr.Use(middleware.apiKeyAuth)
  22. sr.Use(middleware.basicAuth)
  23. sr.Methods(http.MethodOptions)
  24. sr.HandleFunc("/users", handler.createUser).Methods(http.MethodPost)
  25. sr.HandleFunc("/users", handler.users).Methods(http.MethodGet)
  26. sr.HandleFunc("/users/{userID:[0-9]+}", handler.userByID).Methods(http.MethodGet)
  27. sr.HandleFunc("/users/{userID:[0-9]+}", handler.updateUser).Methods(http.MethodPut)
  28. sr.HandleFunc("/users/{userID:[0-9]+}", handler.removeUser).Methods(http.MethodDelete)
  29. sr.HandleFunc("/users/{userID:[0-9]+}/mark-all-as-read", handler.markUserAsRead).Methods(http.MethodPut)
  30. sr.HandleFunc("/users/{username}", handler.userByUsername).Methods(http.MethodGet)
  31. sr.HandleFunc("/me", handler.currentUser).Methods(http.MethodGet)
  32. sr.HandleFunc("/categories", handler.createCategory).Methods(http.MethodPost)
  33. sr.HandleFunc("/categories", handler.getCategories).Methods(http.MethodGet)
  34. sr.HandleFunc("/categories/{categoryID}", handler.updateCategory).Methods(http.MethodPut)
  35. sr.HandleFunc("/categories/{categoryID}", handler.removeCategory).Methods(http.MethodDelete)
  36. sr.HandleFunc("/categories/{categoryID}/mark-all-as-read", handler.markCategoryAsRead).Methods(http.MethodPut)
  37. sr.HandleFunc("/categories/{categoryID}/feeds", handler.getCategoryFeeds).Methods(http.MethodGet)
  38. sr.HandleFunc("/categories/{categoryID}/entries", handler.getCategoryEntries).Methods(http.MethodGet)
  39. sr.HandleFunc("/categories/{categoryID}/entries/{entryID}", handler.getCategoryEntry).Methods(http.MethodGet)
  40. sr.HandleFunc("/discover", handler.discoverSubscriptions).Methods(http.MethodPost)
  41. sr.HandleFunc("/feeds", handler.createFeed).Methods(http.MethodPost)
  42. sr.HandleFunc("/feeds", handler.getFeeds).Methods(http.MethodGet)
  43. sr.HandleFunc("/feeds/counters", handler.fetchCounters).Methods(http.MethodGet)
  44. sr.HandleFunc("/feeds/refresh", handler.refreshAllFeeds).Methods(http.MethodPut)
  45. sr.HandleFunc("/feeds/{feedID}/refresh", handler.refreshFeed).Methods(http.MethodPut)
  46. sr.HandleFunc("/feeds/{feedID}", handler.getFeed).Methods(http.MethodGet)
  47. sr.HandleFunc("/feeds/{feedID}", handler.updateFeed).Methods(http.MethodPut)
  48. sr.HandleFunc("/feeds/{feedID}", handler.removeFeed).Methods(http.MethodDelete)
  49. sr.HandleFunc("/feeds/{feedID}/icon", handler.feedIcon).Methods(http.MethodGet)
  50. sr.HandleFunc("/feeds/{feedID}/mark-all-as-read", handler.markFeedAsRead).Methods(http.MethodPut)
  51. sr.HandleFunc("/export", handler.exportFeeds).Methods(http.MethodGet)
  52. sr.HandleFunc("/import", handler.importFeeds).Methods(http.MethodPost)
  53. sr.HandleFunc("/feeds/{feedID}/entries", handler.getFeedEntries).Methods(http.MethodGet)
  54. sr.HandleFunc("/feeds/{feedID}/entries/{entryID}", handler.getFeedEntry).Methods(http.MethodGet)
  55. sr.HandleFunc("/entries", handler.getEntries).Methods(http.MethodGet)
  56. sr.HandleFunc("/entries", handler.setEntryStatus).Methods(http.MethodPut)
  57. sr.HandleFunc("/entries/{entryID}", handler.getEntry).Methods(http.MethodGet)
  58. sr.HandleFunc("/entries/{entryID}/bookmark", handler.toggleBookmark).Methods(http.MethodPut)
  59. sr.HandleFunc("/entries/{entryID}/fetch-content", handler.fetchContent).Methods(http.MethodGet)
  60. }