angel3_framework
package from pub.dev
.Angel3
as backend server.vim
. Windows users should instead use Notepad++
. Alternative programs will be mentioned where relevant.pubspec.yaml
file, and enter the following contents:dart pub get
, which will install the angel3_framework
library, and its related dependencies:Angel3
can speak different protocols, but more often than not, we'll want it to speak HTTP.bin
, and a file within bin
named main.dart
.bin/main.dart
:dart bin/main.dart
. Your server will now be running, and will listen for input until you kill it by entering Control-C
(the SIGINT
signal) into the terminal.3000
.Hello, world!
message.http.startServer
(or else it will never run).bin/main.dart
should now look like the following:curl localhost:3000 && echo
, you'll see the message Hello, world!
printed to your terminal!app.get
'/'
,req
and res
res.write('Hello, world!')
, which is also the return value of the aforementioned closure.Angel.get
is one of several methods (addRoute
, post
, patch
, delete
, head
, get
) that can be used to add routes that correspond to HTTP methods to an Angel
server instance.'/'
, this signifies that whenever a request is sent to the root of our server, which in this case is the URL http://localhost:3000
, the attached closure should be invoked.http://localhost:3000/foo
, we'd just see a blank line printed again, because there is no route mounted corresponding to the path '/foo'
.req
and res
, hold the types RequestContext
and ResponseContext
, respectively. We'll briefly cover these in the next section.res.write
, which, as you may have surmised, prints a value to the outgoing HTTP response. That's how we are able to print Hello, world!
.RequestContext
and ResponseContext
classes are abstractions used to read and write data on the Web.Angel3
has built-in functionality for parsing bodies of three MIME types:application/json
application/x-www-form-urlencoded
multipart/form-data
'/greet'
for a POST
request, and then attempt to parse the incoming reques t body.name
value from the body, and computes a greeting string.curl
command:Hello, Bob!
appear in your terminal.AngelHttpException
class, or sent as-is if they are already instances of AngelHttpException
.Accept
header). In many cases, however, you might want to do something else, i.e. rendering an error page, or logging errors through a service like Sentry.errorHandler
of your Angel
instance. It is a function that accepts 3 parameters:AngelHttpException
RequestContext
ResponseContext
400 Bad Request
and see our error handler in action, run the following:'Oops! You forgot to include your name.'
printed to the console.angel3_*
packages on the Pub.dev site, and read the documentation found in their respective README
files.