Building a bookmarks API using Actix-web
We'll create a REST API server that allows you to store bookmarks and links to any blog or website that you wish to read later. We'll name our server linksnap
. Let's create a new project by running cargo new linksnap
. In this implementation, we won't be using a database for persistence for any link that is sent to our API, and will simply use an in-memory HashMap
to store our entries. This means that every time our server restarts, all of the stored bookmarks will get removed.
Under the linksnap/
directory, we have the following contents in Cargo.toml
:
# linksnap/Cargo.toml [dependencies] actix = "0.7" actix-web = "0.7" futures = "0.1" env_logger = "0.5" bytes = "0.4" serde = "1.0.80" serde_json = "1.0.33" serde_derive = "1.0.80" url = "1.7.2" log = "0.4.6" chrono = "0.4.6"
We'll implement the following endpoints in our API server:
/links
is aGET
method that retrieves a list of all links stored on the server./add
is aPOST
method that stores an entry...