CRUD Operations Using GOA Framework — Part II
Build your api’s using GOA framework
NOTE: Part-II
just includes adding services for updating records and deleting the added records
Now let’s write methods for update and delete as we did for create and list by updating the design.go
file
We can now run the goa example
command to generate the implementation of the new service added along with buildable server files that spins up goroutines to start a HTTP.
NOTE: But here we need to delete the file book.go
and generate the file again by taking the backup of book.go
because if not deleted, on executing the goa example
command it will not get generated as we already have the file and hence the code will not get updated to the latest services added.
Once deleted and back up is taken we can now run the goa example
command
Edit the file book.go
by copying the following code
Run the generated server as follows
go build ./cmd/book
# Run the server./book[bookapi] 18:02:39 HTTP "Create" mounted on POST /
[bookapi] 18:02:39 HTTP "List" mounted on GET /books
[bookapi] 18:02:39 HTTP server listening on "localhost:8000"
Add a record as discussed in Part I
Before updating let’s see the records:
Now let’s update the records by making an api call with PATCH
method
Let’s see list the record to see the updated record
Finally let’s move to the last operation of deletion by making an api call with DELETE
method
And now we have deleted the record with id
as 1
.
Hence we have complete all the CRUD operations using GOA
framework