What considerations would you take into account when designing the URI scheme of a RESTful API?
- Use descriptive resource names.
- Include sensitive data in URIs.
- Use query parameters for all filtering and sorting needs.
- Avoid using hierarchical URIs.
When designing the URI scheme of a RESTful API, using descriptive resource names is a best practice. It makes the API more intuitive and understandable for clients. Including sensitive data in URIs is generally a security risk and should be avoided. Instead, sensitive data should be sent in the request body or headers. Using query parameters for filtering and sorting is a common practice as it keeps the URIs cleaner and allows clients to specify their filtering criteria. Avoiding hierarchical URIs is not a general best practice, as hierarchical structures can be useful in representing relationships between resources.
What is the command to download and install the dependencies of a Go module?
- go install
- go get
- go download
- go mod tidy
The command to download and install the dependencies of a Go module is go get. When you run go get, it reads the dependencies from the go.mod file of the current module and downloads them into your project's GOPATH. This command also updates the go.sum file to ensure the security and integrity of the downloaded packages. It's a common practice to use go get to fetch and manage dependencies in Go projects.
The _____ method in Go is used to decode a JSON document into a struct.
- json.Unmarshal
- json.Decode
- json.UnmarshalFile
- json.Parse
In Go, the json.Unmarshal method from the encoding/json package is used to decode a JSON document into a struct. This method takes the JSON data as input and unmarshals it into a Go struct, effectively mapping the JSON fields to struct fields. This is a fundamental operation when working with JSON data in Go, allowing you to work with structured data easily.
How do you specify a specific version of a dependency using Go Modules?
- Using the 'require' directive
- Using the 'replace' directive
- Using the 'exclude' directive
- Using the 'import' directive
To specify a specific version of a dependency using Go Modules, you use the 'require' directive in the go.mod file. You list the module path and the desired version, ensuring that the version adheres to semantic versioning (SemVer). This allows Go Modules to fetch the correct version of the dependency when you build your project. This precise versioning is essential for ensuring consistency and predictability in your project's dependencies.