Skip to content

REST API for managing job listings built with Go and PostgreSQL, featuring CRUD operations and Postman integration examples

License

Notifications You must be signed in to change notification settings

nabilshadman/go-rest-api-jobs-data

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JobAPI: Go-Powered REST Service

License: MIT Go Postgres Version

Overview

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.

Key Features

  • 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

Technical Implementation

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

Tech Stack

  • 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.

Environment Setup

Prerequisites

  1. Go (Golang)

  2. 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
  3. Postman

    • Install Postman for API testing and development
  4. Database Setup

    • Create a free database instance on ElephantSQL
    • Execute the following SQL to create the jobs table:
      CREATE TABLE jobs (
          # Table schema here
      );

Configuration

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.

Run Application

To start and test the application:

1. Build and Run

Launch the application by running the following command in your terminal:

go build && ./jobs-list

2. Access the API

You can access the API in two ways:

Browser

Open your web browser and navigate to:

http://localhost:8000/jobs

Postman

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.

Examples

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.

Create a Job

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).

Read Jobs

To retrieve all jobs:

GET http://localhost:8000/jobs

To retrieve a specific job by ID:

GET http://localhost:8000/jobs/1

Update a Job

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"
}

Delete a Job

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.

Screenshots

Visual walkthrough of the API's core functionality:

1. Server running on localhost:8000 2. GET /jobs - Retrieving all jobs
3. GET /jobs/{id} - Retrieving specific job 4. POST /jobs - Creating new job
5. Server response for job creation 6. PUT /jobs - Updating existing job
7. Server response for job update 8. DELETE /jobs/{id} - Removing job
9. Server response for job deletion 10. Final PostgreSQL database state

Contributing

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.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Citation

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}
}

About

REST API for managing job listings built with Go and PostgreSQL, featuring CRUD operations and Postman integration examples

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages