2018-11-11 13:22:47 -05:00
|
|
|
// Copyright 2018 Frédéric Guillot. All rights reserved.
|
|
|
|
// Use of this source code is governed by the Apache 2.0
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package api // import "miniflux.app/api"
|
|
|
|
|
|
|
|
import (
|
2020-06-22 00:13:00 -04:00
|
|
|
"net/http"
|
|
|
|
|
2018-11-11 13:22:47 -05:00
|
|
|
"miniflux.app/reader/feed"
|
|
|
|
"miniflux.app/storage"
|
2020-02-26 16:32:18 -05:00
|
|
|
"miniflux.app/worker"
|
2018-11-11 13:22:47 -05:00
|
|
|
|
|
|
|
"github.com/gorilla/mux"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Serve declares API routes for the application.
|
2020-02-26 16:32:18 -05:00
|
|
|
func Serve(router *mux.Router, store *storage.Storage, pool *worker.Pool, feedHandler *feed.Handler) {
|
|
|
|
handler := &handler{store, pool, feedHandler}
|
2018-11-11 13:22:47 -05:00
|
|
|
|
|
|
|
sr := router.PathPrefix("/v1").Subrouter()
|
2020-03-01 20:38:29 -05:00
|
|
|
middleware := newMiddleware(store)
|
2020-06-16 13:05:07 -04:00
|
|
|
sr.Use(middleware.handleCORS)
|
2020-03-01 20:38:29 -05:00
|
|
|
sr.Use(middleware.apiKeyAuth)
|
|
|
|
sr.Use(middleware.basicAuth)
|
2020-06-22 00:13:00 -04:00
|
|
|
sr.Methods(http.MethodOptions)
|
|
|
|
sr.HandleFunc("/users", handler.createUser).Methods(http.MethodPost)
|
|
|
|
sr.HandleFunc("/users", handler.users).Methods(http.MethodGet)
|
|
|
|
sr.HandleFunc("/users/{userID:[0-9]+}", handler.userByID).Methods(http.MethodGet)
|
|
|
|
sr.HandleFunc("/users/{userID:[0-9]+}", handler.updateUser).Methods(http.MethodPut)
|
|
|
|
sr.HandleFunc("/users/{userID:[0-9]+}", handler.removeUser).Methods(http.MethodDelete)
|
|
|
|
sr.HandleFunc("/users/{username}", handler.userByUsername).Methods(http.MethodGet)
|
|
|
|
sr.HandleFunc("/me", handler.currentUser).Methods(http.MethodGet)
|
|
|
|
sr.HandleFunc("/categories", handler.createCategory).Methods(http.MethodPost)
|
|
|
|
sr.HandleFunc("/categories", handler.getCategories).Methods(http.MethodGet)
|
|
|
|
sr.HandleFunc("/categories/{categoryID}", handler.updateCategory).Methods(http.MethodPut)
|
|
|
|
sr.HandleFunc("/categories/{categoryID}", handler.removeCategory).Methods(http.MethodDelete)
|
|
|
|
sr.HandleFunc("/discover", handler.getSubscriptions).Methods(http.MethodPost)
|
|
|
|
sr.HandleFunc("/feeds", handler.createFeed).Methods(http.MethodPost)
|
|
|
|
sr.HandleFunc("/feeds", handler.getFeeds).Methods(http.MethodGet)
|
|
|
|
sr.HandleFunc("/feeds/refresh", handler.refreshAllFeeds).Methods(http.MethodPut)
|
|
|
|
sr.HandleFunc("/feeds/{feedID}/refresh", handler.refreshFeed).Methods(http.MethodPut)
|
|
|
|
sr.HandleFunc("/feeds/{feedID}", handler.getFeed).Methods(http.MethodGet)
|
|
|
|
sr.HandleFunc("/feeds/{feedID}", handler.updateFeed).Methods(http.MethodPut)
|
|
|
|
sr.HandleFunc("/feeds/{feedID}", handler.removeFeed).Methods(http.MethodDelete)
|
|
|
|
sr.HandleFunc("/feeds/{feedID}/icon", handler.feedIcon).Methods(http.MethodGet)
|
|
|
|
sr.HandleFunc("/export", handler.exportFeeds).Methods(http.MethodGet)
|
|
|
|
sr.HandleFunc("/import", handler.importFeeds).Methods(http.MethodPost)
|
|
|
|
sr.HandleFunc("/feeds/{feedID}/entries", handler.getFeedEntries).Methods(http.MethodGet)
|
|
|
|
sr.HandleFunc("/feeds/{feedID}/entries/{entryID}", handler.getFeedEntry).Methods(http.MethodGet)
|
|
|
|
sr.HandleFunc("/entries", handler.getEntries).Methods(http.MethodGet)
|
|
|
|
sr.HandleFunc("/entries", handler.setEntryStatus).Methods(http.MethodPut)
|
|
|
|
sr.HandleFunc("/entries/{entryID}", handler.getEntry).Methods(http.MethodGet)
|
|
|
|
sr.HandleFunc("/entries/{entryID}/bookmark", handler.toggleBookmark).Methods(http.MethodPut)
|
2018-11-11 13:22:47 -05:00
|
|
|
}
|