api.go 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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/reader/feed"
  8. "miniflux.app/storage"
  9. "miniflux.app/worker"
  10. "github.com/gorilla/mux"
  11. )
  12. // Serve declares API routes for the application.
  13. func Serve(router *mux.Router, store *storage.Storage, pool *worker.Pool, feedHandler *feed.Handler) {
  14. handler := &handler{store, pool, feedHandler}
  15. sr := router.PathPrefix("/v1").Subrouter()
  16. middleware := newMiddleware(store)
  17. sr.Use(middleware.handleCORS)
  18. sr.Use(middleware.apiKeyAuth)
  19. sr.Use(middleware.basicAuth)
  20. sr.Methods(http.MethodOptions)
  21. sr.HandleFunc("/users", handler.createUser).Methods(http.MethodPost)
  22. sr.HandleFunc("/users", handler.users).Methods(http.MethodGet)
  23. sr.HandleFunc("/users/{userID:[0-9]+}", handler.userByID).Methods(http.MethodGet)
  24. sr.HandleFunc("/users/{userID:[0-9]+}", handler.updateUser).Methods(http.MethodPut)
  25. sr.HandleFunc("/users/{userID:[0-9]+}", handler.removeUser).Methods(http.MethodDelete)
  26. sr.HandleFunc("/users/{username}", handler.userByUsername).Methods(http.MethodGet)
  27. sr.HandleFunc("/me", handler.currentUser).Methods(http.MethodGet)
  28. sr.HandleFunc("/categories", handler.createCategory).Methods(http.MethodPost)
  29. sr.HandleFunc("/categories", handler.getCategories).Methods(http.MethodGet)
  30. sr.HandleFunc("/categories/{categoryID}", handler.updateCategory).Methods(http.MethodPut)
  31. sr.HandleFunc("/categories/{categoryID}", handler.removeCategory).Methods(http.MethodDelete)
  32. sr.HandleFunc("/discover", handler.getSubscriptions).Methods(http.MethodPost)
  33. sr.HandleFunc("/feeds", handler.createFeed).Methods(http.MethodPost)
  34. sr.HandleFunc("/feeds", handler.getFeeds).Methods(http.MethodGet)
  35. sr.HandleFunc("/feeds/refresh", handler.refreshAllFeeds).Methods(http.MethodPut)
  36. sr.HandleFunc("/feeds/{feedID}/refresh", handler.refreshFeed).Methods(http.MethodPut)
  37. sr.HandleFunc("/feeds/{feedID}", handler.getFeed).Methods(http.MethodGet)
  38. sr.HandleFunc("/feeds/{feedID}", handler.updateFeed).Methods(http.MethodPut)
  39. sr.HandleFunc("/feeds/{feedID}", handler.removeFeed).Methods(http.MethodDelete)
  40. sr.HandleFunc("/feeds/{feedID}/icon", handler.feedIcon).Methods(http.MethodGet)
  41. sr.HandleFunc("/export", handler.exportFeeds).Methods(http.MethodGet)
  42. sr.HandleFunc("/import", handler.importFeeds).Methods(http.MethodPost)
  43. sr.HandleFunc("/feeds/{feedID}/entries", handler.getFeedEntries).Methods(http.MethodGet)
  44. sr.HandleFunc("/feeds/{feedID}/entries/{entryID}", handler.getFeedEntry).Methods(http.MethodGet)
  45. sr.HandleFunc("/entries", handler.getEntries).Methods(http.MethodGet)
  46. sr.HandleFunc("/entries", handler.setEntryStatus).Methods(http.MethodPut)
  47. sr.HandleFunc("/entries/{entryID}", handler.getEntry).Methods(http.MethodGet)
  48. sr.HandleFunc("/entries/{entryID}/bookmark", handler.toggleBookmark).Methods(http.MethodPut)
  49. }