JobAPI is a high-performance REST service built with Go (Golang) that provides comprehensive job management capabilities. The service offers streamlined CRUD operations (Create, Read, Update, Delete) for job listings, leveraging PostgreSQL for robust data persistence and Go's powerful concurrency features for efficient request handling.
- Data modeling using Go structs and slices for efficient data manipulation
- API endpoint routing and handler function implementation
- Modular and maintainable code architecture
- Integration with PostgreSQL for persistent data storage
The API leverages several key technologies and packages:
- gorilla/mux for robust routing capabilities
- Environment variable management
- HTTP request handling
- JSON encoding/decoding
- Type checking and string conversion utilities
- Go (Golang)
- PostgreSQL
- Postman (API testing)
This REST API serves as a practical demonstration of building scalable web services with Go while following best practices in API design and database integration.
-
Go (Golang)
- Download and install from Go's official website
-
Required Go Packages
go get github.com/gorilla/mux # HTTP router and URL matcher go get github.com/subosito/gotenv # Environment variable loader go get github.com/lib/pq # PostgreSQL driver
-
Postman
- Install Postman for API testing and development
-
Database Setup
- Create a free database instance on ElephantSQL
- Execute the following SQL to create the jobs table:
CREATE TABLE jobs ( # Table schema here );
Create a .env
file in your project root with the following:
ELEPHANTSQL_URL="your_database_url_here"
With these components in place, you'll have a complete development environment for running and testing the API.
To start and test the application:
Launch the application by running the following command in your terminal:
go build && ./jobs-list
You can access the API in two ways:
Open your web browser and navigate to:
http://localhost:8000/jobs
Alternatively, use Postman to send requests:
GET http://localhost:8000/jobs
Note: The application runs on port 8000 by default. Make sure this port is available on your system.
We recommend using Postman to make requests to the REST API. You can use either the desktop agent or browser version to send GET, POST, PUT, or DELETE requests.
To create a new job posting:
POST http://localhost:8000/jobs
Request body:
{
"title": "Software Engineer",
"company": "LLM AI",
"location": "San Francisco, CA",
"type": "Full-time"
}
The server will return a response containing the newly created job's ID (assumed to be 8 in subsequent examples).
To retrieve all jobs:
GET http://localhost:8000/jobs
To retrieve a specific job by ID:
GET http://localhost:8000/jobs/1
To update an existing job:
PUT http://localhost:8000/jobs
Request body:
{
"id": 8,
"title": "Machine Learning Engineer",
"company": "LLM AI",
"location": "New York, NY",
"type": "Full-time"
}
To delete a job by ID:
DELETE http://localhost:8000/jobs/8
For more detailed examples of using our API with Postman, check out our demo.
Visual walkthrough of the API's core functionality:
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
This project is licensed under the MIT License. See the LICENSE file for details.
If you use this work in your research, please cite:
@misc{job-api-go,
author = {Shadman, Nabil},
title = {JobAPI: Go-Powered REST Service},
year = {2021},
publisher = {GitHub},
url = {https://github.com/nabilshadman/go-rest-api-jobs-data}
}